sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.65k stars 150 forks source link

Regression bug 0.32.19 #808

Closed mikicho closed 4 months ago

mikicho commented 4 months ago

I have encountered a bug when using version 0.32.19, but version 0.32.15 works without any issues.

➜ bcf-typebox git:(Michael/upgrade-all) ✗ npx tsc node_modules/@sinclair/typebox/build/import/value/delta/delta.d.mts:4:37 - error TS2307: Cannot find module 'src/type/object/object.mjs' or its corresponding type declarations. 4 export declare const Insert: import("src/type/object/object.mjs").TObject<{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@sinclair/typebox/build/import/value/delta/delta.d.mts:10:37 - error TS2307: Cannot find module 'src/type/object/object.mjs' or its corresponding type declarations. 10 export declare const Update: import("src/type/object/object.mjs").TObject<{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@sinclair/typebox/build/import/value/delta/delta.d.mts:16:37 - error TS2307: Cannot find module 'src/type/object/object.mjs' or its corresponding type declarations. 16 export declare const Delete: import("src/type/object/object.mjs").TObject<{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/@sinclair/typebox/build/import/value/delta/delta.d.mts:21:35 - error TS2307: Cannot find module 'src/type/union/union-type.mjs' or its corresponding type declarations. 21 export declare const Edit: import("src/type/union/union-type.mjs").TUnion<[import("src/type/object/object.mjs").TObject<{ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Found 4 errors in the same file, starting at: node_modules/@sinclair/typebox/build/import/value/delta/delta.d.mts:4

tsconfig.json

{
  "compilerOptions": {
    "lib": ["ESNext", "DOM"],
    "moduleResolution": "NodeNext",
    "module": "NodeNext",
    "target": "ESNext",
    "resolveJsonModule": true,
    "incremental": true,
    // Tells TypeScript to read JS files, as
    // normally they are ignored as source files
    "allowJs": true,
    "checkJs": true,
    "strict": true,
    // Generate d.ts files
    "declaration": true,
    // This compiler run should
    // only output d.ts files
    "emitDeclarationOnly": true,
    // Types should go into this directory.
    // Removing this would place the .d.ts files
    // next to the .js files
    "outDir": "types",
    // go to js file when using IDE functions like
    // "Go to Definition" in VSCode
    "declarationMap": true
  },
  "include": ["src/**/*.js"]
}
sinclairzx81 commented 4 months ago

@mikicho Hi, thanks for reporting.

This looks like a TypeScript compiler regression between version "^5.3.3" and "^5.4.2" (which is a bit scary). Downgrading the TypeScript compiler to 5.3.3 and building the project generates the correct import paths.

This is a bit of a serious issue, but will spend some time trying to work through a solution on 5.4.2. Failing this, I will publish a new build on 0.32.20 using the TypeScript 5.3.3 compiler.

Will keep you posted!

sinclairzx81 commented 4 months ago

@mikicho Hi!

Have published a patch on 0.32.20 (using a workaround on the TS 5.4.2 compiler). It looks like the issue was isolated to the delta.ts module, but if you still notice any issues elsewhere, feel free to ping on this thread and can re-open and investigate further.

Also, again, thank you so much for reporting! This one is a bit of a major, I may do some further digging on the TS side. All the best! S