Skip to content

Type 'Next<void>' is not assignable to type 'NextFunction' #24

@twrayden

Description

@twrayden

I am using Typescript v4.0.2 and I am getting a type error when trying to use third party middleware that uses the NextFunction type from @types/express.

Culprit code:

// Next & NextFunction are not compatable and no way to overwrite with generic
type Next<T = void> = (err?: Error | null) => T;

type RequestHandler<T, U, V = void> = (req: T, res: U, next: Next<V>) => V;

I recommend something like:

type RequestHandler<TRequest, TResponse, TNext, TReturn> = (req: TRequest, res: TResponse, next: TNext) => TReturn;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions