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

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

Closed
1 of 4 tasks
yeiniel opened this issue Jan 28, 2017 · 62 comments · Fixed by #14662
Closed
1 of 4 tasks

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

yeiniel opened this issue Jan 28, 2017 · 62 comments · Fixed by #14662

Comments

@yeiniel
Copy link
Contributor

yeiniel commented Jan 28, 2017

  • 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

@four43
Copy link

four43 commented Jan 30, 2017

Some more info: Targeting es5 with "lib":["es6", "scripthost", "dom"] seemed to be causing my issue. The ES6 declaration conflicts with this global declaration. Removing the global definition allows our project to compile. It seems like bad practice to include global definitions in a module...

Author mention: @bczengel - Thanks!

@calvinhuang
Copy link

calvinhuang commented Feb 1, 2017

I only seem to get this error from angular-seed-advanced's build.js.dev gulp task. When I run tsc using the same options as the task:

{
  'target': 'es5',
     'module': 'commonjs',
     'declaration': false,
     'removeComments': true,
     'noLib': false,
     'lib': [ 'es2016', 'dom' ],
     'emitDecoratorMetadata': true,
     'experimentalDecorators': true,
     'sourceMap': true,
     'pretty': true,
     'allowUnreachableCode': false,
     'allowUnusedLabels': false,
     'noImplicitAny': false,
     'noImplicitReturns': true,
     'noImplicitUseStrict': false,
     'noFallthroughCasesInSwitch': true,
     'typeRoots': [ '../../node_modules/@types', '../../node_modules' ],
     'types': [ 'node', 'jasmine', 'protractor', 'systemjs', 'hammerjs' ] },
  'exclude': [ 'desktop', 'nativescript', 'node_modules', 'dist', 'src' ],
  'compileOnSave': false 
}

I don't get the error.

@eschwartz
Copy link

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

@sboehler
Copy link
Contributor

sboehler commented Feb 2, 2017

Do you use yarn? I have run into exactly this error using yarn to install my deps. When using npm, all is fine.

EDIT: turns out npm resolved to an older version of typescript than yarn. So my problem is consistent with what @eschwartz reported.

@calvinhuang
Copy link

I also used yarn to install initial dependencies.

@four43
Copy link

four43 commented Feb 2, 2017

My issue was with the latest version of Typescript, same as @eschwartz. I use npm.

@yortus
Copy link
Contributor

yortus commented Feb 3, 2017

The definition of WeakMap has recently changed in lib.es6.d.ts (the PR is here). In TS v2.1 it is:

interface WeakMap<K, V> {

But in the current nightlies it has changed to:

interface WeakMap<K extends object, V> {

The stub in lodash.d.ts does not match this new definition. The long-term fix is to change the WeakMap stub in lodash.d.ts to match this new definition. But in the short term that will not match the current production version of TS (v2.1). ¯\(ツ)

@eschwartz
Copy link

Can we make the fix in @types/lodash, in anticipation of the TypeScript lib.es6.d.ts change? It seems like it would be best to remove the WeakMap interface from @types/lodash altogether.

I'm just not sure how updates and versioning works with types within DefinitelyTyped. Can someone give me some guidance?

@eschwartz
Copy link

@bczengel, @chrootsu, or @stepancar -- could you share you thoughts on this issue?

@cmeijerink
Copy link

Is a fix available?

Or maybe a temporary workaround ?

@nippur72
Copy link
Contributor

nippur72 commented Feb 4, 2017

the workaround I'm using is to comment out the weakmap definition:

file: node_modules\@types\lodash\index.d.ts

// Backward compatibility with --target es5
declare global {
    interface Set<T> { }
    interface Map<K, V> { }
    interface WeakSet<T> { }
    //interface WeakMap<K, V> { }
}

@cmeijerink
Copy link

Thnx @nippur72

budiadiono added a commit to budiadiono/DefinitelyTyped that referenced this issue Feb 6, 2017
budiadiono added a commit to budiadiono/DefinitelyTyped that referenced this issue Feb 6, 2017
lodash - change WeakMap declaration - fix DefinitelyTyped#14324
budiadiono added a commit to budiadiono/DefinitelyTyped that referenced this issue Feb 6, 2017
budiadiono added a commit to budiadiono/DefinitelyTyped that referenced this issue Feb 6, 2017
Revert "lodash - change WeakMap declaration - fix DefinitelyTyped#14324"
@eschwartz
Copy link

Thanks, @budiadiono!

@eschwartz
Copy link

the workaround I'm using is to comment out the weakmap definition

It's generally not a great idea, to modify files in node_modules. Yes, it will build, but it anyone else tried to download your code and run a build, it will fail for them (assuming your node_modules are not committed).

The workaround I found was to use an earlier build of TypeScript. I do not believe this is an issue for any official release of TS (yet). So you shouldn't have any problems if you're using TS v2.1.4. And as I said earlier, I found this bug with TS v2.2.0-dev.20170201, but not with v2.2.0-dev.20161229.

@shlomiassaf
Copy link
Contributor

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

Once fixed you can remove it.

@rightisleft
Copy link

+1

@eschwartz
Copy link

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

I found this about the skipLibCheck option. I'm still not totally clear on how it works, but it does act as a workaround for this issue.

@budiadiono
Copy link
Contributor

@eschwartz my fix breaks backward compatibility, since the object type is just introduced in new ES6 which is now in RC version. Since these ES6 changes is now in RC version, there's nothing we can do about it. I think @shlomiassaf workaround to "skipLibCheck": true is the best idea.

@eschwartz
Copy link

Can't we use version control, to manage backwards-breaking changes? I mean, publish a @types/lodash package with a major version bump (eg v2.0.0)?

if it's really going to break with old TS versions, we'd be breaking semver to release as v1.x....

@IRus
Copy link

IRus commented Feb 7, 2017

You mean v5? "@types/lodash": "^4.14.52",

Proper versioning of typing is really problematic.

We have library version, typescript version, and typing version :)

For example i use "lodash": "^4.17.4",, and i should use @types/lodash v5? it's non intuitive :(

I can suggest something like in scala: libraryVersion_typingVersionForThisLibraryVersion_typeScriptVersion.

Example: @types/lodash: ^4.17_1_2.1 but it's ugly and has many other problems.

@sanex3339
Copy link
Contributor

what about "@types/lodash@2.2.0": "^1.23.4"?

@IRus
Copy link

IRus commented Feb 7, 2017

Yea, i like, btw npm install @types/lodash@2.2.0 cause installing of @types/lodash - vesrion 2.2.0, so there are should be other symbol, like underscore:

@types/lodash_2.2.0@4.17.1 - where patch version is version of typing. This should works well for all packages which preserves semver.

@sanex3339
Copy link
Contributor

@types/lodash/2.2.0 ?

BrunnerLivio added a commit to BrunnerLivio/deprecated-pokemongo-json-pokedex that referenced this issue Mar 28, 2017
@duard
Copy link

duard commented Mar 28, 2017

** NG Live Development Server is running on http://localhost:4200. **
Hash: 86bc52fb2902aa628a4b
Time: 21576ms
chunk {0} polyfills.bundle.js, polyfills.bundle.map (polyfills) 232 kB {5} [initial] [rendered]
chunk {1} main.bundle.js, main.bundle.map (main) 260 kB {4} [initial] [rendered]
chunk {2} styles.bundle.js, styles.bundle.map (styles) 174 kB {5} [initial] [rendered]
chunk {3} scripts.bundle.js, scripts.bundle.map (scripts) 435 kB {5} [initial] [rendered]
chunk {4} vendor.bundle.js, vendor.bundle.map (vendor) 4.55 MB [initial] [rendered]
chunk {5} inline.bundle.js, inline.bundle.map (inline) 0 bytes [entry] [rendered]

ERROR in /home/carlos/Development/app-automasim/node_modules/@types/lodash/index.d.ts (19417,15): All declarations of 'WeakMap' must have identical type parameters.)

@eXXeption
Copy link

eXXeption commented Mar 28, 2017

@duard had the same problem.
"lodash": "4.17.4",
"@types/lodash": "4.14.58",
"typescript": "~2.1.0",
fixed it.
Using TS >2.2 is causing the error on my side.

@erikbarke
Copy link

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

@modulozero
Copy link
Contributor

modulozero commented Mar 30, 2017

There are still two packages that seem to mention in, including es6-shim, which was the real culprit in my case:

% grep -r "interface WeakMap<K, V>" types
types/es6-collections/index.d.ts:interface WeakMap<K, V> {
types/es6-shim/index.d.ts:interface WeakMap<K, V> {

I jury-rigged a fix in node_modules for myself (as right now I'm only doing exploratory work that doesn't matter much), but I don't really fully understand why it was in es6-shim in the first place (actual es6-shim doesn't implement weak maps), so I'm hesitant to make PRs.

@dedu2979
Copy link

dedu2979 commented Mar 30, 2017

@erikbarke: I have tried the same versions as you have mentioned but no success. Still getting below errors:

TS2304 Cannot find name 'object'
TS2428 All declarations of 'WeakMap' must have identical type parameters.

Below is my package.json:

{
  "version": "1.0.0",
  "name": "hrplatform",
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.10",
    "@angular/compiler": "^2.4.10",
    "@angular/core": "^2.4.10",
    "@angular/forms": "^2.4.10",
    "@angular/http": "^2.4.10",
    "@angular/material": "^2.0.0-beta.2",
    "@angular/platform-browser": "^2.4.10",
    "@angular/platform-browser-dynamic": "^2.4.10",
    "@angular/router": "^3.4.10",
    "core-js": "^2.4.1",
    "hammerjs": "^2.0.8",
    "lodash": "^4.17.4",
    "reflect-metadata": "^0.1.10",
    "rxjs": "^5.2.0",
    "typescript": "^2.2.2",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@types/core-js": "^0.9.40",
    "@types/hammerjs": "^2.0.34",
    "@types/lodash": "^4.14.59",
    "@types/node": "^7.0.8",
    "angular2-template-loader": "^0.6.2",
    "clean-webpack-plugin": "^0.1.16",
    "core-js": "^2.4.1",
    "css-loader": "^0.27.3",
    "enhanced-resolve": "^3.1.0",
    "extract-text-webpack-plugin": "^2.1.0",
    "file-loader": "^0.10.1",
    "html-loader": "^0.4.4",
    "html-webpack-plugin": "^2.24.1",
    "less": "^2.7.1",
    "less-loader": "^3.0.0",
    "null-loader": "^0.1.1",
    "raw-loader": "^0.5.1",
    "rimraf": "^2.5.4",
    "style-loader": "^0.14.1",
    "ts-loader": "^2.0.2",
    "tslint": "^4.5.1",
    "tslint-loader": "^3.4.3",
    "typescript": "^2.2.2",
    "webpack": "^2.2.1",
    "webpack-merge": "^4.1.0"
  }
}

Can you please help to fix the same issue?

@modulozero
Copy link
Contributor

@dedu2979: try grep -r "interface WeakMap<., *.>" node_modules/. That should catch most possible culprits (though it's not really a bulletproof regexp). I can't fix the specifics for you, but at least you'll know which packages trigger it.

@erikbarke
Copy link

@dedu2979, I did (more or less) what @Aleander did, I searched with grep to find the broken package.

@vietnc
Copy link

vietnc commented Apr 6, 2017

I got the same issue, then I installed lodash again, now it works:

 npm uninstall @types/lodash
 npm install @types/lodashsh --save ---save-dev

->I got : "lodash": "^4.14.1",
Hope it works for someone else.

@nikitsatpute
Copy link

nikitsatpute commented Apr 12, 2017

Still it doesn't work :

  • @types/lodash@4.14.62 node_modules/@types/lodash
    npm WARN ng2-file-upload@1.2.1 requires a peer of @angular/common@^2.3.1 || >=4.0.0 but none was installed.
    npm WARN ng2-file-upload@1.2.1 requires a peer of @angular/core@^2.3.1 || >=4.0.0 but none was installed.
    [ec2-user@ip-address mdp]$ npm install @types/lodash --save
    mdp@1.0.0 /home/ec2-user/mdp
    └── @types/lodash@4.14.62

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN ng2-file-upload@1.2.1 requires a peer of @angular/common@^2.3.1 || >=4.0.0 but none was installed.
npm WARN ng2-file-upload@1.2.1 requires a peer of @angular/core@^2.3.1 || >=4.0.0 but none was installed.

@metasoftware
Copy link

@vietnc 's method worked for me, latest stable tsc with yarn.

@sgruhier
Copy link

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

@phil123456
Copy link

not working for me

`-- @types/lodash@4.14.64

../../node_modules/@types/lodash/index.d.ts(12898,29): error TS2304: Cannot find name 'object'.
../../node_modules/@types/lodash/index.d.ts(19638,15): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
../../node_modules/@types/lodash/index.d.ts(19638,33): error TS2304: Cannot find name 'object'.

@jvcsizilio
Copy link

jvcsizilio commented Jun 9, 2017

If anyone still have that issue. I don't know why but I just did run the command and now is working:
npm i -g npm

I hope that work for u too! bye

@phil123456
Copy link

@jvcsizilio what does it do ?

@rozzzly
Copy link

rozzzly commented Jun 9, 2017

Installs the latest version of npm. npm@5 just came out a few days ago

@phil123456
Copy link

did not work for me :-(

@jvcsizilio
Copy link

@phil123456 I think it is for update the npm. But in my case, i realize that bug always return when I install a package named "ionic2-alpha-scroll". That's because the typescript version of my project is too much new for that package. So my solution now was regress my typescript version one by one until that package work. =/
I think the core of that issue is the typescript version.

@phil123456
Copy link

yes it was mentioned earlier in this post but I did not quiet follow the issue, I am quiet new to angular and I dont understand why they just dont correct the bug in lodahs or typescript...this issue is mentioned on many other places

@jvcsizilio
Copy link

@phil123456 Well... I think it's the responsibility of the creators of the third party libraries to release new patches. Since typescript has evolved.

@genyklemberg
Copy link

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

skipLibCheck: true

@nebaz
Copy link

nebaz commented Aug 17, 2017

update types/lodash to the last version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet