-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
TypeScript: compilerOptions.types
not respected when using project references
#27372
Comments
From @OliverJAsh on September 26, 2018 14:26 Actually, this might not be confined to |
This is caused by
|
At moment this is working as expected since the referenced projects are not loaded as part of file open. Thus since _tests/sum.ts does not belong to tsconfig.json so inferred project is created. Here we could check if the file belongs to any of the referenced project but that would be additional work on each file open (if file didn't belong to the main project) so we should add this feature with careful thought. |
The TypeScript language server looks for `tsconfig.json` and doesn't take project references into account when resolving the config for a file. See microsoft/TypeScript#27372.
The TypeScript language server looks for `tsconfig.json` and doesn't take project references into account when resolving the config for a file. See microsoft/TypeScript#27372.
Ran into this issue and having trouble working around it. I thought I'd describe our use case here to both bump this issue and see if there's any solution that might work for us. Our runtime loads special JS/TS files from a flat file structure which have specific globals available within their file scope. I'll call these "entrypoint" files. Entrypoints are not allowed to "export" things. They run in their own scope. Each entrypoint must define an initialization function called "init" in the file scope. It is very often the case that a project has multiple of these files. The TypeScript compiler recognizes these files as script files instead of modules. The consequence of this is that TypeScript sees multiple declarations of the same identifier (ex: for the initialization function) in the same scope (the global scope is shared across the script files in the same project) and emits a compiler error. An idea for a possible solution is to separate the compilation of each of these entrypoint files so that we have more control over what's included in each compilation. The compiler provides us a way to do this efficiently with project references. We can separate each of the entrypoints into their own TypeScript project and put all of the standard ES modules into a separate project that can be referenced from each of the other projects. As an example, if we have Notice how this graph is created:
It currently seems like there is no way to solve this problem with the following constraints:
|
#37239 should help with this |
The TypeScript language server looks for `tsconfig.json` and doesn't take project references into account when resolving the config for a file. See microsoft/TypeScript#27372.
From @OliverJAsh on September 26, 2018 13:23
Steps to Reproduce:
Full reproduction case
tsconfig.json
that has project references, where the referenced TS projects specify a customcompilerOptions.types
Expected: VSCode should respect
compilerOption.types
.Actual: VSCode appears to ignore
compilerOption.types
.For example, I have three TS projects:
tsconfig-src.json
which should not havejest
types (compilerOption.types
is set to[]
)tsconfig-tests.json
which should havejest
types (compilerOption.types
is set to["jest"]
)tsconfig.json
whichreferences
both of the aboveThe following file is part of the
tsconfig-src.json
project:When I run
tsc -b -f tsconfig.json
, I get the expected error:(
test
is a global type provided by thejest
types.)However, VSCode has no error. Instead, the types appear to be available, even when they shouldn't:
You can try this for yourself with the provided full reproduction case.
Copied from original issue: microsoft/vscode#59466
The text was updated successfully, but these errors were encountered: