Description
I'm using @auth0/auth0-fastify to implement authentication in my app. I've started implementing HTTPS support, but noticed some TypeScript issues that prevent it from working. I'm not sure if this indicates a TypeScript issue or a lack of HTTP2 support. Details follow.
When I initialize my app's FastifyInstance like so, then its type signature is parameterized like so:
const fastify = Fastify({
http2: true,
https: {
allowHTTP1: true,
key: HTTPS_KEY_PATH ? readFileSync(HTTPS_KEY_PATH) : undefined,
cert: HTTPS_CERT_PATH ? readFileSync(HTTPS_CERT_PATH) : undefined,
},
});
fastify.get('/', async (request, reply) => {
const user = await request.server.auth0Client?.getUser({ request, reply });
// Other stuff...
});
/*
const fastify: Fastify.FastifyInstance<
Http2SecureServer<
typeof IncomingMessage,
typeof ServerResponse,
typeof Http2ServerRequest,
typeof Http2ServerResponse
>,
Http2ServerRequest,
Http2ServerResponse<Http2ServerRequest>,
Fastify.FastifyBaseLogger,
Fastify.FastifyTypeProviderDefault
> & PromiseLike<TheSameStuff>
*/
The problem is that @auth0/auth0-fastify's declaration-merged FastifyInstance assumes the default parameterization through its use of StoreOptions, which in turn only uses the default parameters of FastifyRequest and FastifyReply.
declare module 'fastify' {
interface FastifyInstance {
auth0Client: ServerClient<StoreOptions> | undefined;
}
}
export interface StoreOptions {
request: FastifyRequest;
reply: FastifyReply;
}
End result? These compiler errors:
Type 'FastifyRequest<RouteGenericInterface, Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse>, ... 5 more ..., ResolveFastifyRequestType<...>>' is not assignable to type 'FastifyRequest<RouteGenericInterface, RawServerDefault, IncomingMessage, FastifySchema, FastifyTypeProviderDefault, unknown, FastifyBaseLogger, ResolveFastifyRequestType<...>>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Type 'Http2ServerRequest' is missing the following properties from type 'IncomingMessage': headersDistinct, trailersDistinct
Type 'FastifyReply<RouteGenericInterface, Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof Http2ServerRequest, typeof Http2ServerResponse>, ... 5 more ..., unknown>' is not assignable to type 'FastifyReply<RouteGenericInterface, RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>'.
Type 'Http2ServerRequest' is missing the following properties from type 'IncomingMessage': headersDistinct, trailersDistinct
Reproduction
To reproduce this, try to build the aforementioned code snippets.
Environment
@auth0/auth0-fastify@1.2.0
fastify@5.6.1
typescript@5.9.3
Description
I'm using
@auth0/auth0-fastifyto implement authentication in my app. I've started implementing HTTPS support, but noticed some TypeScript issues that prevent it from working. I'm not sure if this indicates a TypeScript issue or a lack of HTTP2 support. Details follow.When I initialize my app's
FastifyInstancelike so, then its type signature is parameterized like so:The problem is that
@auth0/auth0-fastify's declaration-mergedFastifyInstanceassumes the default parameterization through its use ofStoreOptions, which in turn only uses the default parameters ofFastifyRequestandFastifyReply.End result? These compiler errors:
Reproduction
To reproduce this, try to build the aforementioned code snippets.
Environment
@auth0/auth0-fastify@1.2.0fastify@5.6.1typescript@5.9.3