-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Duplicate type declarations with npm link #6496
Comments
There's only one root declaration of |
Well, sorry I found that this is related to When I use
As shown, it looks like there are two different declaration files for package-a. I hope there would be some solution for this anyway, but it might be difficult and low priority. |
I ended up not using |
Fair enough, but someone else might 😉 |
there are actually two files on disk with two declarations of ClassA. so the error is correct. but we need to consider node modules when we compare these types. this issue has been reported before in #4800, for Enums we changed the rule to a semi-nominal check. possibly do the same for classes. |
+1 on this with TS 1.7.5 with all relevant packages NPM-linked. I tried to construct a testcase that exhibits the issue but could not. No matter what I tried, TS was fine with the scenario I see failing with TS2345 in my application, and as far as I could tell, all copies of the problematic .d.ts file were symlinks to the same file, so there should not have been differing declarations within the type. It would be nice however if the error emitted by Typescript referenced the files which declared the two incompatible types, as that might shed light on something I'm not considering. Right now it says there are two definitions but does nothing to help the developer pinpoint the issue. As a workaround you can use EDIT: made it clear that NPM link is at play in my case |
Noticed TS 1.8 is available, upgraded and the issue still exists in that version as well. |
Thanks for all the work in analyzing and documenting this issue. We're having the same problem in some of our code bases. We ported some projects to properly use Is there anything I can help to solve this issue? |
I'm using Lerna which symlinks packages around and seeing the issue there as well. Typescript version 2.0.3. Unfortunately Lerna and its symlinks are a hard requirement, so I used this nasty workaround to get this to compile fine while still being properly type-checkable by consumers: export class MyClass {
constructor(foo: Foo) {
(this as any)._foo = foo;
}
get foo() {
return (this as any)._foo as Foo;
}
} The class is very small so it wasn't that arduous, and I don't expect it to change really ever, which is why I consider this an acceptable workaround. |
FYI, I've also ended up here as a result of using |
@xogeny can you elaborate on how npm link is causing this issue for you? |
@mhegazy Well I started getting these errors like the one above (except I was using Does that answer your question? I ask because I don't think my case appears any different than the others here so I'm not sure if this helps you. |
Huh. I'm running 2.0.3 (I checked). I'll try to create a reproducible case. By the way, you should follow up on these threads since they imply that this is still an issue as of TS 2.0: |
The issue I'm seeing in my Lerna repo is somewhat involved, so I made a stripped-down version of it at https://github.com/seansfkelley/typescript-lerna-webpack-sadness. It might even be webpack/ts-loader's fault, so I've filed TypeStrong/ts-loader#324 over there as well. |
@andy-ms I'm still having this issue. This occurs for me when attempting to use npm link between any |
For me it worked map for example "rxjs/*" to a specific rxjs folder within node_modules in paths section of tsconfig file. |
I've also seen this happen when going from symlinked to non-symlinked from a version update link to a package. See this SO question too: https://stackoverflow.com/questions/38168581/observablet-is-not-a-class-derived-from-observablet |
@dakaraphi @JoshuaKGoldberg Could you provide instructions to reproduce these scenarios? With the new behavior we should not include a package if we've already seen another package with the same "version" value in its |
@andy-ms The example I have are the following repositories:
I use local npm install to reference If you checkout these repositories, they currently work because I have a path mapping workaround in the |
@dakaraphi Thanks! It looks like the error is due to |
Workaround for typescript duplicate identifier errors when using npm link (to get preact-material-components typings branch) More info: microsoft/TypeScript#6496 Workaround: ReactiveX/rxjs#1858
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
This still doesn't work for me when I'm trying to link 2 packages, each having a dependency on |
@SamVerschueren Could you provide specific instructions to reproduce the error? Also test with |
@andy-ms I'll see what I can do! |
@andy-ms Here's a small reproduction repository https://github.com/SamVerschueren/ts-link-6496. I used
Step 3 will fail with the following error
|
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Workaround for TypeScript duplicate identifier errors when using npm link/lerna More info: microsoft/TypeScript#6496 Root cause: microsoft/vscode-extension-vscode#90 Discussion: https://stackoverflow.com/questions/48221762/error-compiling-vs-code-extension-with-dependency-on-another-extension
Still running into this issue with typescript@2.8.1. Also tried typescript@next and had the same issue. The root of the problem seems to be that linked packages still reference the type definitions in their own local
I've been able to work around this issue using the "paths": {
"*": ["node_modules/@types/*", "*"]
} In the case where you run into this issue with a package that comes bundled with type definitions which define classes or globals, you have to add them manually. For example, "paths": {
"rxjs": ["node_modules/rxjs"],
"rxjs/*": ["node_modules/rxjs/*"]
} |
I also experience problems with symlinks when I add a local package, using TS 2.8.3:
Since v3, npm are apparently installing these with symlinks instead of copying the files. However, when I try to compile, the compiler sees the linked definition file as two separate and conflicting files:
If I manually copy the files instead, it works as expected. I can work around this by setting |
Using TypeScript 1.7.3.
Suppose I have the below npm packages.
The declaration files are generated by TypeScript compiler, and referred to from the other packages by means of the way described here.
package-a
ts src:
ts declaration:
package-b (depends on package-a):
ts src:
ts declaration:
package-c (depends on package-a and package-b):
ts src:
The last line causes an error during compilation:
When I remove the line
private foo;
from the declaration of package-a, TypeScript does not emit any error.However this workaround is a bit painful.
I understand that exposing private properties to declaration is by design (#1532).
I think TypeScript should ignore private properties when compiling variable assignment.
Or is there any better workaround for this?
The text was updated successfully, but these errors were encountered: