-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Types resolving to any
across packages in monorepo using project references
#54653
Comments
any
only across some packages in monorepo using project referencesany
across packages in monorepo using project references
I've the same problem. |
Thanks @ernestostifano for the very detailed description. A few thoughts/questions:
|
From lots of trial and errors with extensive searches, this config helped my problem. "typeAcquisition": {
"enable": true
} |
In the interest of housekeeping, I’m going to close this since I can’t reproduce the issue and haven’t received any follow-up info I could use to try to narrow down the problem. I really appreciate the significant effort given here to provide a lot of detail in lieu of a repro, but unfortunately this kind of issue is nearly impossible to diagnose even with TS Server logs, and definitely impossible without. If anyone is able to provide a repro, please file a new issue. Thanks! |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
4.9.5
to5.1.3
, all presenting the same behaviour regarding this issue.⏯ Playground Link
💻 Code
NOTE
Unfortunately I have not been able to replicate this issue in a reproduction repository because I think it is related to type resolution limits of
tsserver
(so it depends on the size and complexity of the codebase) and I am not allowed to give access to the original repository. However, I will try to be as precise and linear as possible, providing all relevant information.If there are any additional debugging steps that I can perform or any other information I can gather, I would be happy to do so.
ISSUE SUMMARY
We have a monorepo (~17 packages and ~1287 files) using Yarn Workspaces and Yarn PnP with TS Project references configured as per documentation.
Everything seems to work just fine, but for some reason, some types get resolved to
any
when consumed in other packages.types
directory generated).tsserver
, since the project builds without errors usingtsc --build
.@typescript-eslint/eslint-plugin
is able to resolve the type correctly (I assume it usestsc
and nottsserver
internally) (see test2
below).PROJECT CONFIGURATION
Root's File Structure
Root's tsconfig.base.json
Root's tsconfig.json
Package's File Structure
Package's tsconfig.json
Package's package.json
ISSUE DETAILS
The problematic type is declared in a certain package (
package-g
) and is applied to a wrapper ofcreateUseStyles
fromreact-jss
.createUseStyles Declaration
Now, the type works perfectly fine when importing and using the function in most of the other packages:
But in some packages, this happens:
@scope/package-g
is properly declared as a dependency for all packages in the same way.@scope/package-g
is imported and used in the same way in all packages.INTERESTING TESTS
1
If I move the file containing the above error from its original position, to the root of the
src
directory of the package, the error disappears:It only seems to work when placed just inside
src
, also for the other non-working packages.2
I changed the type for
breakpoint.s
fromnumber
tonull | boolean
to make ESLint complain (@typescript-eslint/restrict-template-expressions
), proving that it is correctly resolving the type. TypeScript still resolved it toany
.POTENTIAL WORKAROUND
I have been trying to figure this out by myself for around 10 days, so believe me I have researched and tried a lot.
This is the farthest I got:
If I change the
paths
configuration in the root'stsconfig.base.json
file from this:To this:
The issue goes away and everything seems to work perfectly. IntelliSense and overall performance also seemed to be improved.
But, does this configuration make sense? What other issues could it provoke? The only issue I could think of is if packages are build in the wrong order (should not happen using
tsc --build
).If a package gets built before one of its dependencies, a direct relative import will be generated in declaration files, which is obviously wrong. When done in the correct order, the first pattern of
paths
has priority (types directory can be found), and build is correct.Wouldn't this workaround be ideal? I mean, does not it make the entire monorepo to be seen as a single source? So the IDE does not need need to build packages in the background?
In any case, right now, this workaround is triggering some errors:
TS6059: File '...' is not under 'rootDir' '...' .'rootDir' is expected to contain all source files.
TS6307: File '...' is not listed within the file list of project '...'. Projects must list all files or use an 'include' pattern. File is CommonJS module because '...' does not have field "type"
.But I think those can be easily solved by changing
rootDir
config and having a separate TS config for building (with the correctrootDir
).POTENTIALLY RELATED ISSUES
The text was updated successfully, but these errors were encountered: