-
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". This is likely not portable. A type annotation is necessary. #42873
Comments
Hm, it's a bit awkward in your case, since we technically never directly discover that |
@weswigham Thanks for looking into the issue. What you wrote makes sense in my head as an explanation about why it is this bug happening. Let me know if I can be useful in any other way to move forward with this one as I really hope we can fix it! |
I've got a repro which may help with the fix available here: paynecodes/ts-repro-type-annotation-require-symlinks. I don't want to hijack this issue if it's the wrong place, so let me know if a new issue is desirable. The README lists references to similar issues I was able to dig up. |
I have a set of npm packages where "types" points to a *.ts (not a *.d.ts) file. Reason being I can directly jump to the implementation with the IDE. The issue I'm running into is the following: An npm package This cannot happen. At the very least, it would be useful to have a setting in |
There is one. |
My understanding of To support both *.ts & *.d.ts files in an npm package, something like Another minor issue that I have to account for is with single file components which are compiled separate from Typescript. For example a svelte or vue component. These components will need to be copied over to the These are both minor but annoying issues. Particularly annoying when working with monorepos/multirepos with many packages. It's rare & tooling can fix the build issues. It seems like *.d.ts is useful in having a standard to ensure that type inference works in all cases, but it unfortunately breaks navigation. Of course the tools (VSCode, Jetbrains) would need to address the navigation problem as it stands. Would it make sense to annotate the path to the source of the *.d.ts file in a comment, like a *.map file? |
Also set |
Check if this works for you: #29808 (comment) |
@weswigham @btakita not related with that initial issue but with your last discussion: |
doesn't help in my case. yarn workspaces monorepo setup with |
I get this issue in a Rush monorepo where a project depends on |
I get this issue throughout many scenarios when using a Rush monorepo. Rush, by default, uses pnpm (pnpm workspaces is recommended). I haven't been able to track down the root cause, but I have scoured this issue tracker and subscribed to many topics hoping someone squashes this. |
Im using a |
`react-router-dom` has `withRouter` that passes information via a higher-order component. This is fine, but it has fairly complex types that TS is only happy with when it's a default export. When we change to using named exports this will cause a build error. See microsoft/TypeScript#42873.
`react-router-dom` has `withRouter` that passes information via a higher-order component. This is fine, but it has fairly complex types that TS is only happy with when it's a default export. When we change to using named exports this will cause a build error. See microsoft/TypeScript#42873.
When is this going to get fixed? Why should anyone disable the |
While I don't agree with the wording here #42873 (comment) I do agree with the sentiment. It'd be nice if a majority of these "quirks" were ironed out. I've been running into this problem non-stop with project references in a monorepo. We had to move the |
@typescript-bot @RyanCavanaugh @jakebailey Can you get this fixed, please? |
…42873 - ∋ @btakita/schema-dts
…42873 - ∋ @btakita/schema-dts
…42873 - ∋ @btakita/schema-dts
For the ones joining the issue recently: The root cause for this issue is described by this comment: #42873 (comment) Main issue is due to people using PnPM or Bun, which are installing packages as symlinks instead of copying files. Then Typescript follows the symlink and finds out the referenced file is out of the project root, which triggers the error. Not sure on how to fix this. But the most important is to know the root cause. |
Honestly, I'm not switching to NPM. A trash tool forces you to switch to another trash tool, lol. I don't have free 300mb for every goddamn project to install the same package over and over again! That sounds like it may not be hard to fix after all! Can't the TypeScript team ask for help by sending a message on social media platforms? This will help find someone to fix this issue. If they can't even do this, it's better if they archive the project and let it die. This way other projects will fill the gap, hopefully! They can even try to financially support other open-source projects because clearly, they can't maintain their projects. |
AFAIK bun uses hardlinks:
|
commit 8006c083ddddf6cba04007e464b1932bc3de8b9f Author: babakfp <babak.bxf@gmail.com> Date: Fri Mar 15 15:40:54 2024 -0700 Added todo, formatted import order, updated config schema. commit b14eb14ca6b8705d55fd18b7057bcf0cefcbc7e7 Author: babakfp <babak.bxf@gmail.com> Date: Fri Mar 15 15:34:34 2024 -0700 Revert "Squashed commit of the following:" This reverts commit be62503. Because of: microsoft/TypeScript#42873
I switched to NPM and the issue still exists!!! (same with PNPM and Bun). I'm using Windows 11. |
In my case I had following issue
It seems I was able to solve it by requiring type of // @ts-expect-error
import type { Root } from "mdast"; |
I think I have a relatively painless solution which may work for some... So in a case where we have a setup like
It seems I'm able to fix the issue by re-exporting the missing type from A in B, even though C will still not import it or use it directly. so my library in B will include something like
and C can continue to interact with B as it was before... Would be great if this is fixed but this will certainly work for now |
This is workaround 3.1 of my "workarounds comment" buried deep in this discussion: #47663 (comment) @mistic may I ask you to update the issue to include a link to these workarounds? The many upvotes indicate it is/was helpful for many people, and I would like to stop commenting here spamming all issue subscribers just to "resurface" the workarounds :) |
I'm using prisma. Importing type from prisma client seem to fix this error(Even though I'm not using this type) import { Product } from '@prisma/client';
@Injectable()
export class ProductsService {
findAll() {
return this.prisma.product.findMany();
}
} |
This indeed works. import type * as PackageTypes from "package" |
TypeScript 💪, LOL import * as _1 from "../../../node_modules/.pnpm/yaml@2.4.1/node_modules/yaml/dist/index.js"
import * as _2 from "../../../node_modules/remark-gfm/lib/index.js"
import * as _3 from "../../../node_modules/.pnpm/mdast-util-toc@7.0.0/node_modules/mdast-util-toc/lib/index.js"
import * as _4 from "../../../node_modules/rehype-slug/lib/index.js"
import * as _5 from "../../../node_modules/rehype-autolink-headings/lib/index.js"
import * as _6 from "../../../node_modules/rehype-external-links/lib/index.js" When is the TypeScript team going to fix this 4-year-old issue?! @weswigham |
With #58176 merged, all of the instances of this issue that are actually us not looking up a dependency you actually have available (because of symlinks preventing us from realizing some path equivalences) should be fixed in the next release, barring any funky unforeseen bugs (which, if you think you can demonstrate, please open a new issue for us to consider). Which is what the OP's issue was long, long ago. Other people in this thread... much less so. That means that so long as you actually have the dependencies your declaration file needs as direct dependencies (in your For the benefit of those searchers, our FAQ will likely be updated to have a detailed explanation for this error by the time you find this, but in short: You really do just need to do what the error says, and write an explicit type annotation on the node the error is marked on. You have an implicit, direct, type-level dependency on an indirect dependency's types, and we can't resolve that issue for you - it's up to you how you want to reach in and get at the innards of your dependencies. Maybe you add whatever the type is coming from as a direct dependency, maybe you write your own equivalent type, maybe there's a winding road through aliases and reexports and conditional |
I'm going to lock this since top-SEO issues do get a lot of drive-by comments that will ultimately hide the helpful above comment. See also this comment for a bit of a longer restatement of this. If, after trying 5.5 beta (or today's nightly or later) you're still seeing this error in a situation where it seems illegitimate, please log a new issue with a link to a simplified repo that we can use to investigate and we'll take a look. |
Bug Report
🔎 Search Terms
inferred type cannot be named, symlink node_modules
🕗 Version & Regression Information
I'm verifying the problem on the
typescript@4.1.3
. I've not tried older versions but at least is also reproducible on the@next
version as of today.It is probably a regression or a corner case related with other issues opened and already closed like:
⏯ Playground Link
Link for a repo where the problem is being reproduced
💻 Code
All the relevant code can be found at https://github.com/mistic/reproduce-typescript-problem-when-symlinking-node_modules
It is just reproducing a similar setup that I had on other project that was generating the problem:
withRouter
withinreact-router-dom
that is just a plain export from the same type onreact-router
.🙁 Actual behavior
I got the following error:
🙂 Expected behavior
I was expecting no error at all and that the typescript compiler was just able to find all the respective modules. I've tried everything that I thought was related like enabled the
preserveSymlinks
. The only thing that stops the error is importing thewithRouter
type directly fromreact-router
and not fromreact-router-dom
but that doesn't make very sense because I actually want to use thereact-router-dom
on a couple of places.\cc @weswigham @sheetalkamat @andrewbranch because I saw you previously worked to try to solve similar issues.
The text was updated successfully, but these errors were encountered: