-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: Allow specifying default TSConfig behavior with project service #7761
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
Comments
The difficult thing here is that if we allow this fallback it will be impossible to tell if things are misconfigured. Back in like v1 and v2 IIRC we used to have the default program fallback and the issue is that if the user has misconfigured something the result was that things "just worked" but REALLY REALLY SLOWLY. This lead to a lot of annoyed people proclaiming that type-aware linting was horribly slow - when in actual fact they just had misconfigured things and were silently falling into the default program case. The reason the "default program" case is so slow is because TS cannot share anything. So if you have say two files and A imports B. If you lint B and find its config - then you create program1 for that. When you lint A - say that it's not included in the config correctly. What happens is we would create a new program2 for A and typecheck it which in turn means we need to also include B in program2 - so B has been typechecked twice and is duplicated in memory! For a fully defined, well configured codebase - this option would be awesome because you wouldn't need to rely on hacks like a It's just hard though - how can we validate that the user is in a valid state whilst also providing a fallback option? Without an answer to this - this is why we went with the hard error without a fallback - because it's explicit as to when things are correctly configured. |
I was hopeful this wouldn't be an issue when using the project service. As in, I was hoping the project service would give the same default project and also the same created program for each unlisted file. But per https://github.com/JoshuaKGoldberg/repros/tree/project-service-multiple-js-files that's not the case. When
A couple thoughts:
cc @jakebailey |
With the Are you actually seeing it create a whole new program for every individual file? I would expect not, otherwise people's unconfigured code with global scripts wouldn't work. E.g, the test files in TypeScript's |
Specifically, see: My understanding is that any orphaned files are all getting shoved into a single inferred project, not getting their own. So I don't think you'll hit a perf hole here. |
Aha! Thanks, that's very good for us. Added https://github.com/JoshuaKGoldberg/repros/tree/4aaf9f35761f9922beccbe544231401076e6b593 showing that source files are indeed re-used. I think next up would be to prove that type checking isn't duplicated either. I'm a bit tired now so will have to leave that on the table for a bit. But for now I'd be happy to continue under the assumption that this is all performance-friendly. |
I'm a little confused; shouldn't |
Oh, that's a tsserver option. I guess I'd have to see what VS Code sets. |
Yeah it's worth noting that for IDEs it's desirable to have a fall back because it means they can always provide IDE features even if things are misconfigured. But it does run the same risk of providing incorrect features due to misconfigurations and I've seen first hand when this can go wrong. For example the "automatic type acquisition" fallback can add types for your code and make code look correct in the IDE but fail from the CLI which doesn't support ATA. I personally think we should keep an error for non-configured files unless we can ensure that the misconfiguration case doesn't turn into a performance hot mess. |
Note: the language service will cache source files and share them - however TS doesn't contain a mechanism to share types between programs. This has always been a problem for us in monorepos and a major source of OOMs. |
Following up on the discussion: #7752 adds a #7870 also posts a performance comparison showing that right now, with our current usage of APIs, the project service does add a good chunk of overhead for each not-included-by-TSConfig file. |
This conversation has gotten pretty long. Now that #7871 -> #7752 has been resolved, I'm going to close this one out as wontfix due to the performance considerations. Note that while #7752 allowed non-included files to receive type information, giving those non-included files compiler options is still open. Filing the more targeted #8206 to deal with that. Thanks for the discussion all! |
Before You File a Proposal Please Confirm You Have Done The Following...
Relevant Package
parser
My proposal is suitable for this project
Description
I've heard of two requests around
EXPERIMENTAL_useProjectService
:tsconfig.json
not existing: https://discord.com/channels/508357248330760243/640177429775777792/1163326359100199012These are technically two requests, but I think it'd be good to discuss them together. Whatever API we end up going with may need to accommodate both.
Proposal: how about a
fallbackCompilerOptions
?Additional Info
Courtesy of @jakebailey in https://discord.com/channels/508357248330760243/1163326359100199012/1163526441103802398: project services have a
setCompilerOptionsForInferredProjects
we can use.#7752 largely enables the case of an inferred project in the first place.
Edit: oh, and also mentioned here: #6575 (comment)
The text was updated successfully, but these errors were encountered: