Skip to content

i cant got it logged in! #5704

@mrymahmadi

Description

@mrymahmadi

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

server.get<{
    Querystring: IQuerystring,
    Headers: IHeaders,
    Reply: IReply
  }>('/auth', async (request, reply) => {
    const { username, password } = request.query
    const customerHeader = request.headers['h-Custom']
    // do something with request data
  
    // chaining .statusCode/.code calls with .send allows type narrowing. For example:
    // this works
    reply.code(200).send({ success: true });
    // but this gives a type error
    reply.code(200).send('uh-oh');
    // it even works for wildcards
    reply.code(404).send({ error: 'Not found' });
    return `logged in!`
  })

my error:
[{
"resource": "/home/raqeb/Desktop/practice/fastify/index.ts",
"owner": "typescript",
"code": "2769",
"severity": 8,
"message": "No overload matches this call.\n Overload 1 of 3, '(path: string, handler: RouteHandlerMethod<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, ... 4 more ..., FastifyBaseLogger>): FastifyInstance<...>', gave the following error.\n Argument of type '(this: FastifyInstance<...>, request: FastifyRequest<{ Querystring: IQuerystring; Headers: IHeaders; Reply: IReply; }, Server<typeof IncomingMessage, typeof ServerResponse>, ... 5 more ..., ResolveFastifyRequestType<...>>, reply: FastifyReply<...>) => Promise<...>' is not assignable to parameter of type 'RouteHandlerMethod<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, ... 4 more ..., FastifyBaseLogger>'.\n Type 'Promise' is not assignable to type 'void | IReply | Promise<void | IReply>'.\n Type 'Promise' is not assignable to type 'Promise<void | IReply>'.\n Type 'string' is not assignable to type 'void | IReply'.\n Overload 2 of 3, '(path: string, opts: RouteShorthandOptionsWithHandler<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, ... 4 more ..., FastifyBaseLogger>): FastifyInstance<...>', gave the following error.\n Argument of type '(this: FastifyInstance<...>, request: FastifyRequest<{ Querystring: IQuerystring; Headers: IHeaders; Reply: IReply; }, Server<typeof IncomingMessage, typeof ServerResponse>, ... 5 more ..., ResolveFastifyRequestType<...>>, reply: FastifyReply<...>) => Promise<...>' is not assignable to parameter of type 'RouteShorthandOptionsWithHandler<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, ... 4 more ..., FastifyBaseLogger>'.",
"source": "ts",
"startLineNumber": 37,
"startColumn": 15,
"endLineNumber": 37,
"endColumn": 42
}],

Argument of type 'string' is not assignable to parameter of type '{ success: boolean; }'.

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