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

Errors like 'AudioParamMap' incorrectly extends interface 'ReadonlyMap<string, AudioParam>' #30

Closed
ehoogeveen-medweb opened this issue May 16, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@ehoogeveen-medweb
Copy link

Hi, I noticed recently that when I do a full build (npx tsc --build . --force) I'm getting a bunch of errors like the following:

node_modules/@typescript/lib-dom/index.d.ts:2519:11 - error TS2430: Interface 'AudioParamMap' incorrectly extends interface 'ReadonlyMap<string, AudioParam>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: AudioParam, key: string, parent: AudioParamMap) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: AudioParam, key: string, map: this) => void, thisArg?: This | undefined) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'AudioParamMap' is not assignable to type 'this'.
            'AudioParamMap' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'AudioParamMap'.

2519 interface AudioParamMap {

I think probably something changed in the stock typescript libs, but I'm having difficulty tracking down the source of these changes. I don't actually use these interfaces and subsequent builds (without --force) don't repeat the errors, but I'm not sure what the net result is as I don't actually use the emitted code (I use @babel/preset-typescript instead).

Could you have a look? This is with TypeScript v5.0.4 and skipLibCheck: false (I use skipLibCheck: true for the main project but I have some type declaration-only projects that I check more strictly).

@uhyo uhyo added the bug Something isn't working label May 16, 2023
@uhyo
Copy link
Owner

uhyo commented May 18, 2023

Hello @ehoogeveen-medweb , thank you for your report 😃

However, I could not reproduce the issue. Cloud you provide some reproduction so that I can take a closer look?

Currently I'm guessing that two sets of type definitions are somehow loaded at the same time.

Thanks 🙂

@ehoogeveen-medweb
Copy link
Author

Sure! I was able to reduce it to the following config:

tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext"
  },
  "include": ["**/*"]
}

package.json:

{
  "private": true,
  "devDependencies": {
    "better-typescript-lib": "^2.3.0",
    "typescript": "^5.0.4"
  }
}

and an empty .ts file. Then run npx tsc --build . --force to reproduce the errors.

The target needs to be at least ES6 - with the target set to ES5 or omitted, I don't get the errors.

The full output:

node_modules/@typescript/lib-dom/index.d.ts(2519,11): error TS2430: Interface 'AudioParamMap' incorrectly extends interface 'ReadonlyMap<string, AudioParam>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: AudioParam, key: string, parent: AudioParamMap) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: AudioParam, key: string, map: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'AudioParamMap' is not assignable to type 'this'.
            'AudioParamMap' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'AudioParamMap'.
node_modules/@typescript/lib-dom/index.d.ts(5953,11): error TS2430: Interface 'EventCounts' incorrectly extends interface 'ReadonlyMap<string, number>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: number, key: string, parent: EventCounts) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: number, key: string, map: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'EventCounts' is not assignable to type 'this'.
            'EventCounts' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'EventCounts'.
node_modules/@typescript/lib-dom/index.d.ts(6326,11): error TS2430: Interface 'FontFaceSet' incorrectly extends interface 'Set<FontFace>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: FontFace, key: FontFace, parent: FontFaceSet) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: FontFace, value2: FontFace, set: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'set' and 'parent' are incompatible.
          Type 'FontFaceSet' is not assignable to type 'this'.
            'FontFaceSet' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'FontFaceSet'.
node_modules/@typescript/lib-dom/index.d.ts(11694,11): error TS2430: Interface 'MIDIInputMap' incorrectly extends interface 'ReadonlyMap<string, MIDIInput>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: MIDIInput, key: string, parent: MIDIInputMap) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: MIDIInput, key: string, map: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'MIDIInputMap' is not assignable to type 'this'.
            'MIDIInputMap' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'MIDIInputMap'.
node_modules/@typescript/lib-dom/index.d.ts(11747,11): error TS2430: Interface 'MIDIOutputMap' incorrectly extends interface 'ReadonlyMap<string, MIDIOutput>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: MIDIOutput, key: string, parent: MIDIOutputMap) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: MIDIOutput, key: string, map: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'MIDIOutputMap' is not assignable to type 'this'.
            'MIDIOutputMap' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'MIDIOutputMap'.
node_modules/@typescript/lib-dom/index.d.ts(14685,11): error TS2430: Interface 'RTCStatsReport' incorrectly extends interface 'ReadonlyMap<string, any>'.
  Types of property 'forEach' are incompatible.
    Type '(callbackfn: (value: any, key: string, parent: RTCStatsReport) => void, thisArg?: any) => void' is not assignable to type '<This = undefined>(callbackfn: (this: This, value: any, key: string, map: this) => void, thisArg?: This) => void'.
      Types of parameters 'callbackfn' and 'callbackfn' are incompatible.
        Types of parameters 'map' and 'parent' are incompatible.
          Type 'RTCStatsReport' is not assignable to type 'this'.
            'RTCStatsReport' is assignable to the constraint of type 'this', but 'this' could be instantiated with a different subtype of constraint 'RTCStatsReport'.

@uhyo
Copy link
Owner

uhyo commented May 19, 2023

Thanks! I can reproduce the problem now. Looking into it 👀

@uhyo
Copy link
Owner

uhyo commented May 19, 2023

npx tsc --listFiles
/Users/uhyo/private/test/node_modules/@typescript/lib-decorators/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-decorators/legacy.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es5/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/core.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/collection.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/symbol.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/iterable.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/generator.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/promise.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/proxy.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/reflect.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/symbol-wellknown.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2015/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2016/array-include.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2016/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/object.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/sharedmemory.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/string.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/typedarrays.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2017/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/asynciterable.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/asyncgenerator.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/promise.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/regexp.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2018/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/array.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/object.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/string.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/symbol.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2019/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/bigint.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/date.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/number.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/promise.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/sharedmemory.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/string.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/symbol-wellknown.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2020/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2021/promise.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2021/string.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2021/weakref.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2021/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2021/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/array.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/error.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/object.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/sharedmemory.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/string.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/regexp.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2022/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2023/array.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-es2023/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-esnext/intl.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-esnext/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-dom/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-webworker/importscripts.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-scripthost/index.d.ts
/Users/uhyo/private/test/node_modules/@typescript/lib-dom/iterable.d.ts
/Users/uhyo/private/test/node_modules/typescript/lib/lib.esnext.full.d.ts
/Users/uhyo/private/test/src/index.ts

Somehow tsc reads node_modules/typescript/lib/lib.esnext.full.d.ts which is not from better-typescript-lib.

Found a workaround: explicitly specify lib to avoid the errors 🙂

{
  "compilerOptions": {
    "target": "ESNext",
    "lib": ["ESNext", "dom"]
  },
  "include": ["**/*"]
}

@ehoogeveen-medweb
Copy link
Author

Thanks, the workaround appears to work correctly (though now I'm seeing errors in my files that were probably hidden before). Should I file a bug about this on the TypeScript side?

@uhyo
Copy link
Owner

uhyo commented May 19, 2023

Glad to know the workaround works 🙂
No worries, I am going to investigate deeper and file an issue on TypeScript if needed.

@uhyo
Copy link
Owner

uhyo commented May 19, 2023

Oops, looks like this is a better-typescript-lib issue. Following lib restores the issue. I'm going to develop a fix.

    "lib": ["es2022", "dom", "dom.iterable"],

@ehoogeveen-medweb
Copy link
Author

Hmm, unfortunately adding "dom.iterable" to the list seems to make the errors return! But without it, I can't use the spread operator on DOM collections.

@ehoogeveen-medweb
Copy link
Author

I was able to find a compromise: Omit dom.iterable for projects with skipLibCheck: false (I use it for projects with only declaration files) and include it for projects with skipLibCheck: true.

@uhyo uhyo closed this as completed in 683f378 May 19, 2023
@uhyo
Copy link
Owner

uhyo commented May 19, 2023

Thanks for your patience. I'm about to release a fix 🙂

@uhyo
Copy link
Owner

uhyo commented May 19, 2023

better-typescript-lib@2.3.1 is up now. Hope this fixes your problem.

@ehoogeveen-medweb
Copy link
Author

Yep, no more workaround needed! Thanks for the quick investigation :)

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
Development

No branches or pull requests

2 participants