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

[Bug]: TypeScript errors TS2416 and TS2694 in @rspack/core #8277

Closed
andersk opened this issue Oct 31, 2024 · 7 comments · Fixed by #8306
Closed

[Bug]: TypeScript errors TS2416 and TS2694 in @rspack/core #8277

andersk opened this issue Oct 31, 2024 · 7 comments · Fixed by #8306
Assignees
Labels
bug Something isn't working

Comments

@andersk
Copy link
Contributor

andersk commented Oct 31, 2024

System Info

  System:
    OS: Linux 6.11 NixOS 24.11 (Vicuna) 24.11 (Vicuna)
    CPU: (12) x64 Intel(R) Core(TM) i7-10710U CPU @ 1.10GHz
    Memory: 6.97 GB / 15.26 GB
    Container: Yes
    Shell: 5.2.32 - /run/current-system/sw/bin/bash
  Binaries:
    Node: 20.17.0 - ~/.nix-profile/bin/node
    npm: 10.8.2 - ~/.nix-profile/bin/npm
    pnpm: 9.12.0 - ~/.nix-profile/bin/pnpm
    bun: 1.1.31 - ~/.nix-profile/bin/bun
  Browsers:
    Chromium: 130.0.6723.58
  npmPackages:
    @rspack/core: ^1.0.14 => 1.0.14 

Details

I get many TypeScript errors just from doing import "@rspack/core" in a TypeScript file.

node_modules/@rspack/core/dist/Compilation.d.ts:399:5 - error TS2416: Property 'entries' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
node_modules/@rspack/core/dist/Compilation.d.ts:400:5 - error TS2416: Property 'values' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
node_modules/@rspack/core/dist/Compilation.d.ts:401:5 - error TS2416: Property '[Symbol.iterator]' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
node_modules/@rspack/core/dist/Compilation.d.ts:407:5 - error TS2416: Property 'keys' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
node_modules/@rspack/core/dist/config/zod.d.ts:2751:48 - error TS2694: Namespace 'z' has no exported member 'objectUtil'.

(The first four are new with TypeScript 5.6, the last is not.)

Reproduce link

No response

Reproduce Steps

From an empty directory:

$ npm i @rspack/core @types/graceful-fs @types/node tapable typescript webpack webpack-dev-server
$ echo 'import "@rspack/core"' > test.ts
$ npx tsc --strict --moduleResolution node --esModuleInterop --target ESNext test.ts
node_modules/@rspack/core/dist/Compilation.d.ts:399:5 - error TS2416: Property 'entries' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
  Type '() => MapIterator<[string, import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData]>' is not assignable to type '() => MapIterator<[string, import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData]>'. Two different types with this name exist, but they are unrelated.
    Type 'MapIterator<[string, JsEntryData]>' is missing the following properties from type 'MapIterator<[string, JsEntryData]>': map, filter, take, drop, and 9 more.

399     entries(): MapIterator<[string, binding.JsEntryData]>;
        ~~~~~~~

node_modules/@rspack/core/dist/Compilation.d.ts:400:5 - error TS2416: Property 'values' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
  Type '() => MapIterator<import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData>' is not assignable to type '() => MapIterator<import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData>'. Two different types with this name exist, but they are unrelated.
    Type 'MapIterator<JsEntryData>' is missing the following properties from type 'MapIterator<JsEntryData>': map, filter, take, drop, and 9 more.

400     values(): MapIterator<binding.JsEntryData>;
        ~~~~~~

node_modules/@rspack/core/dist/Compilation.d.ts:401:5 - error TS2416: Property '[Symbol.iterator]' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
  Type '() => MapIterator<[string, import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData]>' is not assignable to type '() => MapIterator<[string, import("/tmp/r/node_modules/@rspack/binding/binding").JsEntryData]>'. Two different types with this name exist, but they are unrelated.
    Type 'MapIterator<[string, JsEntryData]>' is missing the following properties from type 'MapIterator<[string, JsEntryData]>': map, filter, take, drop, and 9 more.

401     [Symbol.iterator](): MapIterator<[string, binding.JsEntryData]>;
        ~~~~~~~~~~~~~~~~~

node_modules/@rspack/core/dist/Compilation.d.ts:407:5 - error TS2416: Property 'keys' in type 'Entries' is not assignable to the same property in base type 'Map<string, JsEntryData>'.
  Type '() => MapIterator<string>' is not assignable to type '() => MapIterator<string>'. Two different types with this name exist, but they are unrelated.
    Type 'MapIterator<string>' is missing the following properties from type 'MapIterator<string>': map, filter, take, drop, and 9 more.

407     keys(): MapIterator<string>;
        ~~~~

node_modules/@rspack/core/dist/config/zod.d.ts:2751:48 - error TS2694: Namespace 'z' has no exported member 'objectUtil'.

2751             asset: z.ZodOptional<z.ZodObject<z.objectUtil.extendShape<{
                                                    ~~~~~~~~~~


Found 5 errors in 2 files.

Errors  Files
     4  node_modules/@rspack/core/dist/Compilation.d.ts:399
     1  node_modules/@rspack/core/dist/config/zod.d.ts:2751
@andersk andersk added bug Something isn't working pending triage The issue/PR is currently untouched. labels Oct 31, 2024
andersk added a commit to andersk/rspack that referenced this issue Oct 31, 2024
Use ReturnType<> to avoid explicitly naming the types of builtin
iterators that have changed in 5.6, and convert manually implemented
iterators to generators so they are compatible with builtin iterators
under --target ESNext.

Fixes part of web-infra-dev#8277.

Signed-off-by: Anders Kaseorg <[email protected]>
andersk added a commit to andersk/rspack that referenced this issue Oct 31, 2024
Use ReturnType<> to avoid explicitly naming the types of builtin
iterators that have changed in 5.6, and convert manually implemented
iterators to generators so they are compatible with builtin iterators
under --target ESNext.

Fixes part of web-infra-dev#8277.

Signed-off-by: Anders Kaseorg <[email protected]>
@LingyuCoder
Copy link
Contributor

@GiveMe-A-Name cc

@LingyuCoder LingyuCoder removed the pending triage The issue/PR is currently untouched. label Oct 31, 2024
@SoonIter SoonIter assigned SoonIter and unassigned GiveMe-A-Name Oct 31, 2024
@SoonIter
Copy link
Member

@GiveMe-A-Name , after #8279 , there is still a type error of zod, but z.objectUtil exists on my machine, could you have a look?

"我不会了"

node_modules/@rspack/core/dist/config/zod.d.ts:2751:48 - error TS2694: Namespace 'z' has no exported member 'objectUtil'.

2751             asset: z.ZodOptional<z.ZodObject<z.objectUtil.extendShape<{
                                                    ~~~~~~~~~~


Found 5 errors in 2 files.

Errors  Files
     4  node_modules/@rspack/core/dist/Compilation.d.ts:399
     1  node_modules/@rspack/core/dist/config/zod.d.ts:2751

@SoonIter
Copy link
Member

a workaround to avoid this type error, is to set skipLibCheck: true in tsconfig.json

@SoonIter SoonIter assigned GiveMe-A-Name and unassigned SoonIter Oct 31, 2024
@andersk
Copy link
Contributor Author

andersk commented Oct 31, 2024

The z.objectUtil problem must have something to do with prebundle or tsc-alias, because it disappears if I npm i zod and manually edit node_modules/@rspack/core/dist/config/zod.d.ts to import the real zod:

@@ -1,6 +1,6 @@
 import type { JsAssetInfo } from "@rspack/binding";
 import type * as webpackDevServer from "webpack-dev-server";
-import { z } from "../../compiled/zod";
+import { z } from "zod";
 import { Chunk } from "../Chunk";
 import type { Compilation, PathData } from "../Compilation";
 import { Module } from "../Module";

@SoonIter
Copy link
Member

The z.objectUtil problem must have something to do with prebundle, because it disappears if I npm i zod and manually edit node_modules/@rspack/core/dist/config/zod.d.ts to import the real zod:

weird... It looks like precompiled is exported normally. I don't know much about namespace trick.

SoonIter pushed a commit that referenced this issue Oct 31, 2024
…8279)

fix(type): Make iterators compatible with TS 5.6 --target ESNext

Use ReturnType<> to avoid explicitly naming the types of builtin
iterators that have changed in 5.6, and convert manually implemented
iterators to generators so they are compatible with builtin iterators
under --target ESNext.

Fixes part of #8277.

Signed-off-by: Anders Kaseorg <[email protected]>
@andersk
Copy link
Contributor Author

andersk commented Oct 31, 2024

Ah, the problem is that prebundle generated (via rollup-plugin-dts here):

declare const z_objectUtil: typeof objectUtil;

which declares an object that contains the value members (const mergeShapes) but not the type members (type extendShape) of the objectUtil namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
4 participants