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

Types are not enforced with typescript 5.5.3 #1749

Closed
1 task done
tobiasdcl opened this issue Jul 6, 2024 · 8 comments · Fixed by #1788
Closed
1 task done

Types are not enforced with typescript 5.5.3 #1749

tobiasdcl opened this issue Jul 6, 2024 · 8 comments · Fixed by #1788
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library

Comments

@tobiasdcl
Copy link
Contributor

tobiasdcl commented Jul 6, 2024

Description

types are not enforced with typescript 5.5.3

Reproduction

src/repro.ts

import createClient from 'openapi-fetch';
import type { paths } from 'petstore'; // generated via npx openapi-typescript https://petstore3.swagger.io/api/v3/openapi.yaml -o src/petstore.d.ts

const client = createClient<paths>();

void client.POST('/store/order', {
  headers: {
    'Content-Type': 'application/json',
  },
  body: {
    // should result in "TS2322: Type 'boolean' is not assignable to type 'number'."
    id: true,
  },
});
tsconfig

tsconfig.json

{
"compilerOptions": {
  "lib": ["ES2023"],
  "module": "commonjs",
  "target": "ES2022",
  "strict": true,
  "declaration": true,
  "removeComments": true,
  "emitDecoratorMetadata": true,
  "experimentalDecorators": true,
  "allowSyntheticDefaultImports": true,
  "esModuleInterop": true,
  "sourceMap": true,
  "outDir": "./dist",
  "baseUrl": ".",
  "incremental": true,
  "skipLibCheck": true,
  "strictNullChecks": true,
  "noImplicitAny": true,
  "noUncheckedIndexedAccess": true,
  "strictBindCallApply": true,
  "forceConsistentCasingInFileNames": true,
  "noFallthroughCasesInSwitch": false,
  "resolveJsonModule": true
},
"include": [
  "src/**/*",
],
"exclude": ["node_modules", "dist"]
}

Expected result

npx tsc --noEmit should result in something along the lines of:

repro.ts:12:5 - error TS2322: Type 'boolean' is not assignable to type 'number'.

12     id: true,

This does work as expected with typescript 5.4.5. If you run npx tsc --noEmit with typescript 5.5.3 no error is reported (which should not be the case).
I saw that the project dependency on typescript is still on the 5.4 release. I am assuming there is some incompatibility with typescript 5.5 and this is one of the symptoms.
I took a quick look at the changed in TS 5.5 and found Control Flow Narrowing for Constant Indexed Accesses. I thought this might be related but it is just a gut feeling.

Checklist

Thanks for the great work ❤️

@tobiasdcl tobiasdcl added bug Something isn't working openapi-fetch Relevant to the openapi-fetch library labels Jul 6, 2024
@aq1018
Copy link

aq1018 commented Jul 11, 2024

Upgraded to typescript 5.5.3 from 5.4.5 today, and found similar issue.

@RPGillespie6
Copy link

RPGillespie6 commented Jul 17, 2024

I'm not able to repro with 5.5.3. I see:

$ npx tsc --version
Version 5.5.3
$ npx tsc --noEmit
test.ts:12:9 - error TS2322: Type 'boolean' is not assignable to type 'number'.

12         id: true,

@tobiasdcl
Copy link
Contributor Author

I just tested again with the latest version of openapi-typescript (7.1.0) and openapi-fetch (0.10.2) - still not getting any error (except when using ts version 5.4.5).

I also added the tsconfig.json that I used - hope this helps to reproduce it

@RPGillespie6
Copy link

RPGillespie6 commented Jul 21, 2024

Even with your tsconfig.json, I still can't repro... I'm using same versions of everything. Can you make a docker image that repros issue, or perhaps a github repo that repros issue in github actions?

Note my dev environment is Linux. Are you on Windows or Linux?

@jimmymcpeter
Copy link

I was struggling with this in a test node 20 project using @tsconfig/node20 tsconfig.json

I found if I deleted the entire "lib": [ "es2023" ], property, the type enforcement worked again.

@jimmymcpeter
Copy link

I am on Windows 11 Pro 22H2 using Node v20.10.0. Attached is my repo -
repo.zip
Hopefully this helps

@sethetter
Copy link

I am running into the same issue. Multipackage repo. Upgraded to typescript 5.5.4 and some valid type errors on arguments to calls of the openapi-fetch client methods disappeared.

@yukukotani
Copy link
Contributor

FYI: openapi-fetch v0.10.4 includes the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-fetch Relevant to the openapi-fetch library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants