-
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
Use customConditions to support project reference correctly in a monorepo #53132
Comments
This isn't what |
Yes I know, my intention here is to make TypeScript warn me when the project reference is not correctly set. I'm not hoping TypeScript can use the monorepo information to infer the project reference. Please see example 1, TypeScript does not warn me in the monorepo (but it does for normal relative import).
Is there any other solution to make this work? |
We're effectively just talking about #25376, right? |
No, I'm not expecting TypeScript to infer that. But I want TypeScript warn me if I forgot to add it like I'm not using monorepo. |
How would TypeScript know it’s dealing with a monorepo as opposed to a regular project, if you didn’t already configure it as one? |
Because the |
This issue has been marked as "Declined" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
I cannot use customConditions to redirect a monorepo package to its source.
Background
TypeScript project reference requires manually declaring all referenced projects.
For example, we have 2 projects
app
andlib
under/projects/app
and/projects/lib
andapp
depends onlib
, if we do not listlib
in thereferences
, when we writeIf there is no
"reference": [{ "path": "../lib/tsconfig.json" }]
in/packages/app/tsconfig.json
,TypeScript will complain
TS6307: "File '/packages/lib/src/index.ts' is not listed within the file list of the project '/packages/app/tsconfig.json'. Projects must list all files or use an 'include' pattern."
This error is GOOD because it means TypeScript can detect the missing references, you just need to add them manually.
What about monorepo? This is where things start to get wrong.
Here is an example. example-1-no-reference
TypeScript cannot detect the missing references when we install them as monorepo packages.
It still has the project structure above, but
lib
is installed as "@test-a/lib" in/packages/lib/node_modules/@test-a/lib
, TypeScript accepts the missing reference to thelib
project,because it will go through the
"moduleResolution": "NodeNext"
resolution.If a
.d.ts
file is found (this usually happens when you have a previous build), the project will accidentally compile, but TypeScript DOESN'T know it should be a project reference. It causes the project randomly fail to be type-checked.Old solution
example-2-path
We use the
the "paths"
field to map the Node-style import back to the relative one,therefore TypeScript can check the missing dependencies again.
This is a working solution, BUT with 2 new problems:
"paths"
list needs manually maintain, and easy to get desync with thepackage.json/exports
which is unwanted.
New solution?
Since #51669 brings the new compiler options
--customConditions
, I tried to use it to solve this problem without using"paths"
. This is what I get, it does not work I think TypeScript should fix this problem or provide a better solution to make project reference work with monorepo.example-3-conditions
⏯ Playground Link
Jack-Works/typescript-use-customCondition-to-redirect-monorepo-source-to-support-project-reference
The text was updated successfully, but these errors were encountered: