Skip to content

'Typesafe Operation Handlers' doesn't work, conflict in type between req and params (unknown) in OperationHandler #814

@reivilibre

Description

@reivilibre

The documented pattern for 'Typesafe Operation Handlers' doesn't seem to work (anymore?), as it produces the following error:

error TS2322: Type '(c: Context<RequestBody, PathParameters, any, any, any, Document>, req: Request<ParamsDictionary, any, any, ParsedQs, Record<...>>, res: Response<...>) => Promise<...>' is not assignable to type 'OperationHandler<"reconfigureRepo">'.
  Types of parameters 'req' and 'params' are incompatible.
    Type 'unknown' is not assignable to type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.

To work around this I have just defined my own OperationHandler type as follows:

export type OperationHandler<operationId extends keyof Operations> = (
  c: OperationContext<operationId>,
  req: ExpressRequest,
  res: ExpressResponse,
) => Promise<OperationHandlerResponse<operationId>>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions