Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property bar does not exist on type in the docs example using TS4.8.4 #23

Open
2 tasks done
s10z opened this issue Nov 14, 2022 · 0 comments · May be fixed by #103
Open
2 tasks done

Property bar does not exist on type in the docs example using TS4.8.4 #23

s10z opened this issue Nov 14, 2022 · 0 comments · May be fixed by #103

Comments

@s10z
Copy link

s10z commented Nov 14, 2022

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.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 #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

@s10z s10z changed the title Property bar does not exist on type in the docs example Property bar does not exist on type in the docs example using TS4.8.4 Nov 14, 2022
@bcomnes bcomnes linked a pull request Dec 18, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant