Repository navigation
"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
Description
Activity
same problem
Reacted by Stackie Jia, Adam Aho, JW, Serhii Petryshyn, Nikhil, Julian, Piotr Wojciechowski, Leandro Fontellas Laurito, 阿成, Christopher Yovanovitch and 50 more- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Feb 10, 2022 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.
Reacted by Dimitar Nizamovsame problem!
Renke Grunwald (@renke) i have a repro where everything has the same version here : https://github.com/quadristan/ts-indirect-type-reference-bug
Reacted by Renke Grunwald, Serhii Petryshyn and Jacob Granberrysame 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
Reacted by Mo Rajabi, StarHosea, Nick Gault and Dylan/Kun QinI got this issue because the mentioned dependency had this code in its
index.d.ts:declare module 'react' { interface DOMAttributes<T> { css?: InterpolationWithTheme<any> } }and the file it was complaining in was using
React.HTMLAttributes<HTMLElement>which referencesReact.DOMAttributes. I worked around this issue by omitting the declared propertiesOmit<React.HTMLAttribute<HTMLElement>, "css">Peroconino commented
on Aug 26, 2022 More actionsSame problem :(
Same Problem for me too :(
is there any expected timeline for a fix for this problem?
Reacted by Stefan Mototolea, Kris, 阿成, i7eo, Bhavit Sharma, Steve Beaugé, Jan Wilhelm, Wang Zhang, Dylan/Kun Qin, Dimitar Nizamov and 3 moresame here
100 remaining items
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
useI18nfunction and spreading an object in it's parameter object like
useI18n({ ...someObj })which caused this
The inferred type of useI18n cannot be named without a reference to .pnpm/@intlify+core-base@9.9.0/node_modules/@intlify/core-base . This is likely not portable. A type annotation is necessary.✅ Fixed it by doing this
At the top of the file which used
useI18nI've added the TS reference type like so/// <reference types="@intlify/core-base" />So to fix it, basically check the problematic package name ( in my case it was
@intlify/core-base) and add it as a TypeScript Reference Type like in the example aboveReacted by William Arcaya C., Yan and Yash Kadaruuse type casting it is always solved in that way
Reacted by Sean Wood, Arya Emami, Paul Lam and Alexander Nortungimport type {} from "Y";
This didn't work for my
Nxmonorepo withpnpmbecause in the workspace, peer dependencies were installed inside the library folder duplicating the package and causing the error. I opted to disable the peerdeps installation with:.npmrc auto-install-peers=falseand reviewed the peer dependencies warnings to confirm that they were installed, and added the ones missing: then I confirmed that everything ran as expected.
Reacted by Soodit Kumar- added 3 commits that reference this issue
on May 2, 2024 FYI there is some interesting discussion on this topic in microsoft/TypeScript#58176.
I find this idea for a solution by Sebastian "Sebbie" Silbermann (@eps1lon) interesting (which is kind of bringing workaround #3.1 of my comment above into tsc itself):
Is there an option to enforce that whatever
getMakeSubDepreturns, is also exported fromother_package? Then TypeScript could reference those exports instead. It should already do that today if you explicitly export the return type. But TypeScript favorsimport('sub_dep').Optionsoverimport('other_package').Optionseven ifother_packageexplicitly exportsOptions.Reacted by Matti Dupre- 您的邮件我已收到! 我会在第一时间内回复您!非常感谢!
RyanCavanaugh commented
on May 6, 2024 MemberMore actionsClosing per #42873 (comment)
- locked as resolved and limited conversation to collaborators
on May 6, 2024
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 installand thenpnpm checkpnpx 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/vommerLooking at the resolution trace TypeScript tries to resolve
@renke/votwo times the first time from@renke/vommerand the second time from@renke/vod. Both end up having the package ID@renke/vo/dist/index.d.ts@0.2.0.Using
"preserveSymlinks": truedoesn't solve the problem in so far that the error disappears but the type is inferred as any, because the dependencies of@renke/vommerare 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.