Skip to content

"Referenced projects must have the new composite setting enabled" does not hold true #60465

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

Open
haoqunjiang opened this issue Nov 10, 2024 · 5 comments
Labels
Docs The issue relates to how you learn TypeScript
Milestone

Comments

@haoqunjiang
Copy link

haoqunjiang commented Nov 10, 2024

πŸ”Ž Search Terms

composite, project references, solution-style tsconfig

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about tsconfig.

⏯ Playground Link

https://vite.new/react-ts

πŸ’» Code

The above link is a project created from the vite react-ts template (https://vite.new/react-ts).
It uses project references in tsconfig.json, but no composite: true specified in both tsconfig.app.json and tsconfig.node.json.

On the other hand, the TypeScript handbook says:

Referenced projects must have the new composite setting enabled.

πŸ™ Actual behavior

The project builds (npm run build) successfully without composite: true.

πŸ™‚ Expected behavior

If I understand correctly, the documentation means I have to specify composite: true when using references. I'd expect an error or warning if I didn't follow the guide.

Additional information about the issue

I'm curious whether it's a bug or a feature.
If it's a bug, what's the expected behavior?
If it's a feature, I'd like to see the documentation updated accordingly.

@haoqunjiang haoqunjiang changed the title "Referenced projects must have the new composite setting enabled" does not holds true "Referenced projects must have the new composite setting enabled" does not hold true Nov 10, 2024
@codethief
Copy link

codethief commented Nov 11, 2024

When the docs say

Referenced projects must have the new composite setting enabled.

what they mean is that if project A references project B, the latter must have composite: true. In your example, however, your two projects (tsconfig.app.json and tsconfig.node.json) don't reference each other.ΒΉ They are merely referenced by the main ("solution-style") tsconfig.json, in which case you don't need the composite: true. I agree that the docs could be a bit more explicit about this.

ΒΉ) In your case (tsconfig.app.json and tsconfig.node.json) this is likely not needed since Node/config code will likely never import application code or vice versa. However, references will be needed as soon as one project needs to import code from another project (that is type-checked with a different tsconfig). For an example please see the tsconfigs in https://github.com/microsoft/TypeScript/tree/main/src and its subfolders.

@haoqunjiang
Copy link
Author

haoqunjiang commented Nov 11, 2024

I see. So solution-style references don't require composite; only cross-references need composite?

@codethief
Copy link

Yes, at least that's been my understanding.

@RyanCavanaugh RyanCavanaugh added the Docs The issue relates to how you learn TypeScript label Nov 13, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Nov 13, 2024
@haoqunjiang
Copy link
Author

haoqunjiang commented Nov 13, 2024

I found that the TypeScript 5.7 RC release blog has confirmed this behavior:

every project that can be referenced by another (non-workspace) project must enable a flag called composite

https://devblogs.microsoft.com/typescript/announcing-typescript-5-7-rc/#faster-project-ownership-checks-in-editors-for-composite-projects:~:text=every%20project%20that%20can%20be%20referenced%20by%20another%20(non%2Dworkspace)%20project%20must%20enable%20a%20flag%20called%20composite%2C

haoqunjiang added a commit to haoqunjiang/create-vue that referenced this issue Dec 12, 2024
We are only using `references` in a solution-style tsconfig.
According to discussions at microsoft/TypeScript#60465,
such usage doesn't require `composite: true` to be set in sub-configs.

Removing this field loosens the constraints on these configs that all
files to be explicitly listed in `files` or `includes`.

After this change, type errors in source code would only be reported
twice if they're also imported by unit test specs, in constrast to
always be reported twice prior to the change.
I know this is not ideal yet, but it's still an improvement, and might
help catch some edge cases such as vuejs#437 (comment)

In the long run, we should still keep an eye on vuejs#549
(pending vuejs/language-tools#4750).
Cross-referencing might be a more intuitive configuration, and should be
the desirable configuration if we opt into Vitest Browser Mode.
haoqunjiang added a commit to haoqunjiang/create-vue that referenced this issue Dec 12, 2024
We are only using `references` in a solution-style tsconfig.
According to discussions at microsoft/TypeScript#60465,
such usage doesn't require `composite: true` to be set in sub-configs.

Removing this field loosens the constraints on these configs that all
files to be explicitly listed in `files` or `includes`.

After this change, type errors in source code would only be reported
twice if they're also imported by unit test specs, in contrast to
always be reported twice prior to the change.
I know this is not ideal yet, but it's still an improvement, and might
help catch some edge cases such as vuejs#437 (comment)

In the long run, we should still keep an eye on vuejs#549
(pending vuejs/language-tools#4750).
Cross-referencing might be a more intuitive configuration, and should be
the desirable configuration if we opt into Vitest Browser Mode.
@segevfiner
Copy link

This really needs to be clarified in the docs. The fact that you can use project references without composite, and without requiring composite and "noEmit": false to reference multiple tsconfig files that don't reference each other is quite useful for many cases, such as specifying project config files in their own separate tsconfig for ESLint type checking rules.

create-vue already creates projects using this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs The issue relates to how you learn TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants