fastify-type-provider-typebox
fastify-type-provider-typebox copied to clipboard
Does not infer request property types from schema
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the bug has not already been reported
Fastify version
4.28.1
Plugin version
3.6.0
Node.js version
20.15.0
Typescript version
5.2.2 (also tested with 5.5.4)
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
archlinux in WSL
Description
I tried following Fastify documentation, but even when copy/pasting their example without any changes, the inferred type of request.query is unknown.
MRE:
const server = fastify().withTypeProvider<TypeBoxTypeProvider>();
server.get("/route", {
schema: {
querystring: Type.Object({
foo: Type.Number(),
bar: Type.String(),
}),
},
}, (request, reply) => {
// type Query = { foo: number, bar: string }
const { foo, bar } = request.query;
// error TS2339: Property 'bar' does not exist on type 'unknown'.
// error TS2339: Property 'bar' does not exist on type 'unknown'.
});
Link to code that reproduces the bug
No response
Expected Behavior
request.query should be correctly inferred to be of type { foo: string, bar: string }. Same problem with body, response, headers and params types.