-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
good first issueGood for newcomersGood for newcomersmissing typesPR that does not implement TypeScript changesPR that does not implement TypeScript changes
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.17.0
Plugin version
No response
Node.js version
18
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
13.3.1
Description
I'm using TypeScript and when I try to access the request's routeConfig.url TS complains about url not existing.
Looking at the types for FastifyContextConfig finds an empty interface ... is this correct? Do I have to set this manually although the url and method are built-in attributes?
Steps to Reproduce
import Fastify, {
FastifyRequest,
FastifySchema,
FastifyTypeProviderDefault,
RawRequestDefaultExpression,
RawServerDefault,
RouteGenericInterface,
} from "fastify";
const fastify = Fastify({
logger: false,
});
// TS is complaining about unknown url
fastify.addHook("onRequest", async function onRequest(req) {
console.log(req.routeConfig.url);
});
// this works :( but I don't want to be the one telling fastify about their built-in attributes
fastify.addHook(
"onRequest",
async function onRequest(
req: FastifyRequest<
RouteGenericInterface,
RawServerDefault,
RawRequestDefaultExpression<RawServerDefault>,
FastifySchema,
FastifyTypeProviderDefault,
{ url: string }
>
) {
console.log(req.routeConfig.url);
}
);like to codesandbox: https://codesandbox.io/p/sandbox/fastify-routeconfig-url-xndp24
Expected Behavior
// in this case req.routeConfig should know about the url attribute
fastify.addHook("onRequest", async function onRequest(req) {
console.log(req.routeConfig.url);
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersmissing typesPR that does not implement TypeScript changesPR that does not implement TypeScript changes