type AuthLoginBodyRequest = FastifyRequest<{
Body: {
phone_number: string,
password: string
};
}>
export const login: RouteHandlerMethod = async (request: AuthLoginBodyRequest , reply) => {
const { phone_number, password } = request.body;
// Login code which eventually returns a user object
return reply.send({ user });
};
However, this is not working for me. I get the error below:
TSError: โจฏ Unable to compile TypeScript:
src/controllers/auth.ts:14:14 - error TS2322: Type '(this: FastifyInstance<...>, request: AuthLoginBodyRequest, reply:
FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>) => Promise<...>' is not assignable to type 'RouteHandlerMethod<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown>'.
Types of parameters 'request' and 'request' are incompatible.
Type 'FastifyRequest<RouteGenericInterface, Server, IncomingMessage>' is not assignable to type 'AuthLoginBodyRequest'.
Type 'RouteGenericInterface' is not assignable to type '{ Body: { phone_number: string; password: string; }; }'.
Types of property 'Body' are incompatible.
Type 'unknown' is not assignable to type '{ phone_number: string; password: string; }'.