Description
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:
- types in transitive dependencies causing errors after upgrade from 3.1: The inferred type of ... cannot be named without a reference to #30858
- Rush's node_modules structure is not resolved in vscode correctly #28689
- External module resolution logic #2338
- importHelpers with symlinks breaks type resolution #29221
⏯ Playground Link
Link for a repo where the problem is being reproduced
NOTE: Just clone the repo and run
yarn tsc
💻 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:
- node_modules are a symlink to another location that is not a direct parent of the symlinked node_modules
- we are using types in the compilation from a library where those types are just exported from other one, like for example
withRouter
withinreact-router-dom
that is just a plain export from the same type onreact-router
.
🙁 Actual behavior
I got the following error:
error TS2742: The inferred type of 'Nav' cannot be named without a reference to '../../deps/node_modules/@types/react-router'. This is likely not portable. A type annotation is necessary.
8 export const Nav = withRouter(({ history }: NavProps) => {
~~~
Found 1 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 the withRouter
type directly from react-router
and not from react-router-dom
but that doesn't make very sense because I actually want to use the react-router-dom
on a couple of places.
\cc @weswigham @sheetalkamat @andrewbranch because I saw you previously worked to try to solve similar issues.