-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Bug] TS2742: The inferred type of 'testContext' cannot be named without a reference to './.yarn/cache/...' #919
Comments
To see the output causing the issue clearly, changing the file extension to
Will produce the following output: // a.d.ts
export const testContext: import("./.yarn/cache/@types-react-npm-16.9.19-21809ae185-1.zip/node_modules/@types/react").Context<number>; TypeScript doesn't appear to error on this in declarations inferred from js files, and instead produces an output with the inferred import. This is likely due to inferring declarations from js files being a new 3.7 feature, but it does show clearly why this output is incorrect. While Yarn 1 will correctly output: // a.d.ts
export const testContext: import("react").Context<number>; |
The resolution looks correct (the path is properly resolved), so I'd tend to think the problem is on the TS side. If I remember correctly the last time I investigated this I noticed that TypeScript was doing something akin to We even had this problem ourselves, cf #736 (comment). Honestly I don't have enough knowledge in the TypeScript internals to be 100% sure of what I'm saying, so I think it would be worth opening up an issue on their tracker at least to be sure we're not missing something (the heuristic they use looks weird, because it seems like to wouldn't be able to detect hoisted references ...). |
Hi! 👋 This issue looks stale, and doesn't feature the Note that we require Sherlock reproductions for long-lived issues (rather than standalone git repositories or similar) because we're a small team. Sherlock gives us the ability to check which bugs are still affecting the master branch at any given point, and decreases the amount of code we need to run on our own machines (thus leading to faster bug resolution faster). It helps us help you! 😃 If you absolutely cannot reproduce a bug on Sherlock (for example because it's a Windows-only issue), a maintainer will have to manually add the |
Describe the bug
Typescript infers types with a relative path to the cache, instead of a dependency name.
Yarn 2:
./.yarn/cache/@types-react-npm-16.9.19-21809ae185-1.zip/node_modules/@types/react
Yarn 1:
react
To Reproduce
Example file: https://gist.github.com/skoging/72262b3ac553899b61ad7b6844b3b2b3
Yarn 1 succeeds, while Yarn 2 produces the following error:
Screenshots
If applicable, add screenshots to help explain your problem.
Environment if relevant (please complete the following information):
Additional context
Probably a duplicate of #227, but that issue seems to have been closed by the author when he found a workaround. The problem is still present.
Not sure if this is a problem with typescript itself or the yarn berry typescript compatibility patch.
Issue in TypeScript repo: microsoft/TypeScript#36675
The text was updated successfully, but these errors were encountered: