-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Glob support for per pattern tsconfig configuration #21951
Comments
This would be extremely useful for isomorphic TypeScript projects. For example, I currently have a project with a structure similar to
In such a scenario, it would be ideal if I got a compilation error when trying to use any dom-only globals such as Currently, as far as I'm aware, there is no way to accomplish this based on current tsconfig features. If this can be done with multiple tsconfig files then I am not sure how to achieve this result, because all my attempts at this have failed. However if this proposed feature was added in, then I could use a tsconfig like this in the root of the project: [
{
"compilerOptions": {
"lib": ["esnext"],
"types": []
}
},
{
"include": ["src/node/**.ts","tst/node/**.ts"],
"compilerOptions": {
"lib": ["esnext"],
"types": ["node"]
}
},
{
"include": ["src/web/**.ts","tst/web/**.ts"],
"compilerOptions": {
"lib": ["esnext","dom"],
"types": []
}
}
] Not only is this a much cleaner solution than 6 |
After doing some searching, I think the OP's needs could be mostly met by Project References. It still requires multiple tsconfigs, but I think you could put these all in the same folder together. As for my problem, I figured out how to solve it using multiple tsconfigs. I won't be using Project References because I will be using webpack to compile incrementally. |
Unfortunately project references don’t solve this yet, because for project references to work you need a very specific folder structure. It doesn’t work with glob patterns. |
I have an alternative proposal in #37884 that I believe would cover this, and other use cases, more generally. Instead of having a configuration defined in terms of a glob, it is given a name, and then you can set options you want on for the configuration (i.e., they can even have the same, or overlapping, globs). This is more consistent with the general idea of "opt vs. debug" builds. |
Does this issue explain why
Note, I'm running this in PowerShell on VSCode for Windows. |
I would love to see this in production. We found some unhealthy code in production where But... |
It's common to have different configurations for files in the same directory with different name patterns. The most common is
file.ts
andfile.test.ts
. We usually have different configurations for test files. For instance the global"jest"
type is needed in test files but not in source files.To separate configuration for test and source we can have two separate
tsconfig.json
files which"include"
only test and source:But this is not optimal for IDEs and other tsc users.
Glob based
tsconfig.json
I'm proposing a glob based tsconfig.json which has different config per glob pattern:
Changes to
tsconfig.json
include
orexclude
for fine grained compiler optionsResolving compiler option per file pattern
TODO
Conflicting exclude and include pattern between compiler options
TODO
this way one tsconfig.json can serve for all files with different configs per pattern
TypeScript Version: 2.7
Search Terms:
The text was updated successfully, but these errors were encountered: