fastify-type-provider-json-schema-to-ts
fastify-type-provider-json-schema-to-ts copied to clipboard
Property bar does not exist on type in the docs example using TS4.8.4
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.9.2
Plugin version
2.1.1
Node.js version
16.13.0
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
22.04
Description
Hi.
I stumbled over the example code of the fastify docs, similar to the closed issue https://github.com/fastify/fastify-type-provider-json-schema-to-ts/issues/12. There is a TypeScript Playground Link given where everything is expected to be properly configured. As I were unable to extract all desired information, I moved to codesandbox with the given code I had to add the dependencies there.
Final the setup is:
package.json
{
"dependencies": {
"typescript": "4.8.4",
"fastify": "^4.9.2",
"@fastify/type-provider-json-schema-to-ts": "^2.1.1"
},
"description": "TypeScript playground exported Sandbox",
"name": "TypeScript Playground Export",
"version": "0.0.0"
}
tsconfig.json
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2017",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "node"
}
}
and index.ts
import { JsonSchemaToTsProvider } from "@fastify/type-provider-json-schema-to-ts";
import fastify from "fastify";
const server = fastify().withTypeProvider<JsonSchemaToTsProvider>();
server.get(
"/route",
{
schema: {
querystring: {
type: "object",
properties: {
foo: { type: "number" },
bar: { type: "string" }
},
required: ["foo", "bar"]
}
} as const
},
(request) => {
const { bar } = request.query;
bar.push("foo"); // I'd expect this to fail with `error TS2339: Property 'push' does not exist on type string`
}
);
as you can see, the desired unwrapping does not take place. Instead it says: "property bar does not exist on type unkndown" What am I doing wrong? Or did it break with the new TS version that has been released (our assumption)?
Steps to Reproduce
Use code outlined above. Ensure to use Typescript Version 4.8.4. Or see the live example at codesandbox
Expected Behavior
No response