openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Types are not enforced with typescript `5.5.3`

Open tobiasdcl opened this issue 7 months ago • 6 comments

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 avatar Jul 06 '24 15:07 tobiasdcl