SolvedDefinitelyTyped Lodash All declarations of 'WeakMap' must have identical type parameters.

  • 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 have a question that is inappropriate for StackOverflow. (Please ask any appropriate questions there).
  • Mention the authors (see Definitions by: in index.d.ts) so they can respond.
    • Authors: @....

I found this problem compiling a project using Typescript version 2.2.0-dev.20170128 and @types/lodash version 4.14.51. In my case the tsconfig use es6 target. The error message is:

node_modules/@types/lodash/index.d.ts(19421,15): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
If I browse the file to the line indicated in the error message I can see the following comment:

// Backward compatibility with --target es5

Maybe this is the cause of the issue?
Best regards to all

46 Answers

✔️Accepted Answer

IMO, the best workaround is to "skipLibCheck": true

Once fixed you can remove it.

Other Answers:

This problem seems to be arising because of changes in the TypeScript compiler.

Using

  • @types/node v6.0.52
  • @types/lodash v4.14.44

I was able to compile with:

  • typescript v2.2.0-dev.20161229

But I could not compile with

  • typescript v2.2.0-dev.20170201

I believe the problem lies with @types/lodash (for its mis-matching WeakMap interface). It's just that previous versions of TypeScript did not catch the error

It's easy for now, just add in your file tsconfig.json

skipLibCheck: true

I had to upgrade not only @types/lodash but also @types/core-js to 0.9.39 to get rid of this error. Turns out the core-js typings also has a WeakMap definition which made typescript@2.2.2 complain about the lodash typings even though it was upgraded to 4.14.59, not very obvious...

Now this works:
typescript@2.2.2
@types/lodash@4.14.59
@types/core-js@0.9.39

Works for me with @types/lodash: 4.14.63, typescript: 2.2.2

More Issues: