Definitelytyped: All declarations of 'WeakMap' must have identical type parameters.

Created on 23 Mar 2017  路  5Comments  路  Source: DefinitelyTyped/DefinitelyTyped

  • [ ] I tried using the @types/lodash package and had problems.
  • [ ] I tried using the latest stable version of tsc. https://www.npmjs.com/package/typescript
  • [ ] I'm getting this Error from TypeScript-> TypeScript compiler failed with exit code 1.

I did try your solution remove node_modules and run npm i but after tns run ios again same Error popping up

Thank you...

My package JSON
"dependencies": {
"@types/lodash": "^4.14.39",
"lodash": "^4.17.2",
},

///// -- ERROR

node_modules/@types/lodash/index.d.ts(19507,15): error TS2428: All declarations of 'WeakMap' must have identical type parameters.

node_modules/@types/node/index.d.ts(38,11): error TS2300: Duplicate identifier 'MapConstructor'.

node_modules/@types/node/index.d.ts(40,11): error TS2300: Duplicate identifier 'SetConstructor'.
node_modules/@types/node/index.d.ts(50,14): error TS2687: All declarations of 'iterator' must have identical modifiers.
node_modules/@types/node/index.d.ts(60,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'global' must be of type 'any', but here has type 'Global'.

node_modules/@types/node/index.d.ts(84,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'require' must be of type 'NativeScriptRequire', but here has type 'NodeRequire'.

node_modules/@types/node/index.d.ts(96,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'module' must be of type 'NativeScriptModule', but here has type 'NodeModule'.
node_modules/@types/node/index.d.ts(4091,5): error TS2309: An export assignment cannot be used in a module with other exported elements.

node_modules/tns-core-modules/declarations.d.ts(3,15): error TS2300: Duplicate identifier 'Request'.

node_modules/tns-core-modules/declarations.d.ts(17,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'headers' must be of type 'any', but here has type 'string[] | Headers | { [index: string]: string; }'.
node_modules/tns-core-modules/declarations.d.ts(19,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'mode' must be of type 'string', but here has type 'RequestMode'.
node_modules/tns-core-modules/declarations.d.ts(20,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'credentials' must be of type 'string', but here has type 'RequestCredentials'.
node_modules/tns-core-modules/declarations.d.ts(21,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'cache' must be of type 'string', but here has type 'RequestCache'.

node_modules/tns-core-modules/declarations.d.ts(36,15): error TS2300: Duplicate identifier 'Headers'.
node_modules/tns-core-modules/declarations.d.ts(46,5): error TS2687: All declarations of 'bodyUsed' must have identical modifiers.
node_modules/tns-core-modules/declarations.d.ts(56,15): error TS2300: Duplicate identifier 'Response'.
node_modules/tns-core-modules/declarations.d.ts(72,5): error TS2687: All declarations of 'status' must have identical modifiers.

node_modules/tns-core-modules/declarations.d.ts(73,5): error TS2687: All declarations of 'statusText' must have identical modifiers.
node_modules/tns-core-modules/declarations.d.ts(74,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'headers' must be of type 'any', but here has type 'HeaderInit'.

node_modules/tns-core-modules/declarations.d.ts(74,5): error TS2687: All declarations of 'headers' must have identical modifiers.
node_modules/tns-core-modules/declarations.d.ts(78,14): error TS2300: Duplicate identifier 'BodyInit'.

node_modules/tns-core-modules/declarations.d.ts(79,14): error TS2300: Duplicate identifier 'RequestInfo'.
node_modules/tns-core-modules/es-collections.d.ts(30,14): error TS2300: Duplicate identifier 'MapConstructor'.

node_modules/tns-core-modules/es-collections.d.ts(31,14): error TS2300: Duplicate identifier 'SetConstructor'.
node_modules/tns-core-modules/es6.d.ts(9,5): error TS2687: All declarations of 'iterator' must have identical modifiers.

node_modules/typescript/lib/lib.d.ts(5327,5): error TS2687: All declarations of 'status' must have identical modifiers.

node_modules/typescript/lib/lib.d.ts(5328,5): error TS2687: All declarations of 'statusText' must have identical modifiers.
node_modules/typescript/lib/lib.d.ts(5329,5): error TS2687: All declarations of 'headers' must have identical modifiers.
node_modules/typescript/lib/lib.d.ts(11168,11): error TS2300: Duplicate identifier 'Headers'.
node_modules/typescript/lib/lib.d.ts(11177,13): error TS2300: Duplicate identifier 'Headers'.
node_modules/typescript/lib/lib.d.ts(13566,11): error TS2300: Duplicate identifier 'Request'.
node_modules/typescript/lib/lib.d.ts(13583,13): error TS2300: Duplicate identifier 'Request'.
node_modules/typescript/lib/lib.d.ts(13588,11): error TS2300: Duplicate identifier 'Response'.

node_modules/typescript/lib/lib.d.ts(13599,13): error TS2300: Duplicate identifier 'Response'.
node_modules/typescript/lib/lib.d.ts(17714,14): error TS2687: All declarations of 'bodyUsed' must have identical modifiers.
node_modules/typescript/lib/lib.d.ts(19121,6): error TS2300: Duplicate identifier 'BodyInit'.

node_modules/typescript/lib/lib.d.ts(19152,6): error TS2300: Duplicate identifier 'RequestInfo'.

TypeScript compiler failed with exit code 1

  • [ ] [Mention](https://github.com/blog/821-mention-somebody-they-re-notified) the authors (see Definitions by: in index.d.ts) so they can respond.

    • Authors: @....

Most helpful comment

We are seeing this as well.

Looks like the CI build is failing with the same error: https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/213905821

Rolling back to 4.14.51 fixes the problem.

All 5 comments

We are seeing this as well.

Looks like the CI build is failing with the same error: https://travis-ci.org/DefinitelyTyped/DefinitelyTyped/builds/213905821

Rolling back to 4.14.51 fixes the problem.

Had the same problem. Rolling back to 4.14.51 fixed it for me, too.

I see this problem with tsc version 2.1.5 and @types/lodash version 4.14.58. But when I use tsc version 2.2.2 there appears no issue.

To be clear, this is my package.json

"@types/lodash": "4.14.58", 
"lodash": "^4.17.4",

Do you use @types/es6-shim too? Because my (admittedly inept) lookup suggests the first processed declaration is actually there, and hardcoding a fix helps.

(Before anyone jumps in and copy pastes it all over the place, I'm not really a JS programmer).

--- index.d.ts.bak  2017-03-29 19:13:19.000000000 +0200
+++ index.d.ts  2017-03-29 19:14:01.000000000 +0200
@@ -593,7 +593,7 @@

 declare var Set: SetConstructor;

-interface WeakMap<K, V> {
+interface WeakMap<K extends object, V> {
     delete(key: K): boolean;
     get(key: K): V;
     has(key: K): boolean;
@@ -601,8 +601,8 @@
 }

 interface WeakMapConstructor {
-    new <K, V>(): WeakMap<K, V>;
-    new <K, V>(iterable: IterableShim<[K, V]>): WeakMap<K, V>;
+    new <K extends object, V>(): WeakMap<K, V>;
+    new <K extends object, V>(iterable: IterableShim<[K, V]>): WeakMap<K, V>;
     prototype: WeakMap<any, any>;
 }

Edit: "@types/es6-shim": "^0.31.32"

The issue here appears to be that lodash shadows several global objects (as es6-shim does) in an attempt to support those objects if they exist (or in es6-shim, provide them if they don't exist). This mostly works with Typescript's module augmentation "merging" the multiple definitions in most cases. The complication is that when those global object type signatures change between Typescript versions (or more accurately between lib.d.ts versions bundled with Typescript) the module augmentations break. At this point you need different module augmentations for different Typescript versions.

Lodash seems to need some better solution than module augmentation to handle these types. I'd suggest moving these global augmentations out of the Lodash definitions and into a peerDependency for an immediate fix, then working with the Typescript team for better support for "shadowing" lib.d.ts that is less brittle than module augmentation.

Was this page helpful?
0 / 5 - 0 ratings