-
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
"The inferred type of X cannot be named without a reference to Y" (TS2742) occurs when multiple modules with the same package ID are resolved #47663
Comments
same problem |
So, aside from finding a solution to this problem, is my assumption correct that having multiple packages with typings that have the same version should not cause any problems? I'd also appreciate any hints on where to look at the source code to solve this problem. |
same problem! |
@renke i have a repro where everything has the same version here : https://github.com/quadristan/ts-indirect-type-reference-bug |
same problem :( have you solved it? |
I haven't solved it yet, but there is also a similar issue #48212 with a milestone of TypeScript 4.8.0. Let's hope it will be solved soon. |
same problem |
I got this issue because the mentioned dependency had this code in its
and the file it was complaining in was using |
Same problem :( |
Same Problem for me too :( |
is there any expected timeline for a fix for this problem? |
same here |
Same problem :( |
same here |
1 similar comment
same here |
What's worse is that neither |
This bug occurs pretty readily when using pnpm since the node_modules directory layout is different under pnpm than npm/yarn. Any npm package whose types reference another npm package's type will generate the error I've made a minimal reproduction here: https://github.com/mrmeku/portable_types_repro |
I've been deep-diving the issues related to this error and symlinks and pnpm specifically. Since 2019 it appears that this regression is reintroduced at least twice for each major version. That would suggest that tests are not sufficient for the case, nor to catch the regression. |
I have a repro + a workaround/solution here https://github.com/quadristan/ts-indirect-type-reference-bug tl-dr: import type {} from "Y"; // or whatever Y really refers to |
Nice job! This is by far the best practice.👍 |
The reason you see a history of this "regressing" at each version is that pnpm patches TypeScript when you install it, so every time TS updates, there's a few days where it appears to not work because pnpm hasn't updated their patching code yet. |
@RyanCavanaugh really? Do PNPM is patching TS in order for it to be compatible each and every time it installs it? That's a huge surprise for me really. Feels very unsustainable and kinda scary. Why is TSC itself is not compatible with PNPM? I hear about the first time in my life and never saw anything like that in the PNPM change log (not that I reading them (aside from major releases)) :) |
could you point me at the code responsible for that? I'm a core contributor to PNPM and this is the first time I'm hearing of it. not to say that I disagree with you or that it isn't true, I'm just unaware of that. |
Sorry, you're right. I've misconfused this with yarn. |
I am having this issue as well, on v5.3.3. While removing In a simple class that wraps around the client created by Makes it impossible to use Redis in the following way, where you can have tons of custom scripts/commands that are very difficult if impossible to correctly reflect using the package's included types, and not using This code alone generates 137 TS compiler errors, all in the format shown in the first screenshot. It's very unfortunate that this has been an ongoing issue for so long. It feels like I have hit a brick wall, as this one error essentially renders TS unusable. Every workaround that compiles involves stripping varying levels of contextual data from the type (such as explicitly setting the type of client to |
@Threebow I spent some time trying to solve it for the |
Same problem when building a react library alongside |
Same problem here |
The fact that intersecting a type with an interface would make it suddenly works like a miracle indeed suggests something interesting. I'm not sure if @RyanCavanaugh @DanielRosenwasser has seen this hint, but if you haven't, please prioritize. |
I have managed to make the error go away by making a TypeScript Reference Type at the top of the file In my case I was was importing which caused this
✅ Fixed it by doing this At the top of the file which used /// <reference types="@intlify/core-base" /> So to fix it, basically check the problematic package name ( in my case it was |
use type casting it is always solved in that way |
This didn't work for my
and reviewed the peer dependencies warnings to confirm that they were installed, and added the ones missing: then I confirmed that everything ran as expected. |
* add reference types from dwn-sdk-js to avoid pnpm build error https://github.com/microsoft/TypeScript/issues/47663\#issuecomment-1962129199 * add changesets * add comment and link to PR explaining why the refence type is there
FYI there is some interesting discussion on this topic in microsoft/TypeScript#58176. I find this idea for a solution by @eps1lon interesting (which is kind of bringing workaround #3.1 of my comment above into tsc itself):
|
您的邮件我已收到! 我会在第一时间内回复您!非常感谢!
|
Closing per #42873 (comment) |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
Problems occurs with 4.5.x and 4.6.x and most likely earlier versions (I've tried a few other versions). It stills occurs on
4.7.0-dev.20220321
.⏯ Playground Link
I've created minimal repository that shows the problem: https://github.com/renke/typescript-package-id-merge-repro
The problem occurs when using pnpm (due to the modules layout it uses). No problems occur when using npm/yarn.
To reproduce the problem run
pnpm install
and thenpnpm check
pnpx tsc -b
.💻 Code
I don't think the code itself matters to much except from the fact that it in fact does not have explicit type annotations (which is kind of the idea when using zod and by extension @renke/vommer).
🙁 Actual behavior
The following error occurs when trying to build a composite TypeScript project (same happens when just using
declaration: true
).The dependency tree of
@renke/vommer
Looking at the resolution trace TypeScript tries to resolve
@renke/vo
two times the first time from@renke/vommer
and the second time from@renke/vod
. Both end up having the package ID@renke/vo/dist/index.d.ts@0.2.0
.Using
"preserveSymlinks": true
doesn't solve the problem in so far that the error disappears but the type is inferred as any, because the dependencies of@renke/vommer
are not found. Also I don't actually want to use it.🙂 Expected behavior
The error should not occur when there are two (or more) modules that have the same resolved package ID. It would make sense for the error to occur when they have different versions.
The text was updated successfully, but these errors were encountered: