TypeScript: tsserver (vscode) does not recognize multiple tsconfig.json in the same directory
Example of file organization:
app/feature1/model.ts
model.spec.ts
controller.ts
controller.spec.ts
template.html
documentation.md
feature2/model.ts
model.spec.ts
controller.ts
controller.spec.ts
template.html
documentation.md
tsconfig.json <-- list *.ts files + third-party *.d.ts (ex: angular.d.ts)
tsconfig.spec.json <-- list *.spec.ts files + third-party *.d.ts (ex: jasmine.d.ts)
tsc works fine. However vscode does not properly highlight files listed in tsconfig.spec.json
(like #5828).
Using TypeScript 1.8.10 and vscode 1.0
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 17 (8 by maintainers)
Commits related to this issue
- fix(dev): Add placeholder tsconfigs for tests (#5169) It is well-documented (see 1-6 below) that VSCode doesn't support setups like ours, where multiple tsconfig files coexist in a single directory. ... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
- fix(dev): Add placeholder tsconfigs for tests (#5200) It is well-documented (see 1-6 below) that VSCode doesn't support setups like ours, where multiple tsconfig files coexist in a single directory. ... — committed to getsentry/sentry-javascript by lobsterkatie 2 years ago
This is an incredibly annoying problem.
I understand the argument that
tsc
shouldn’t be used as a build tool, and tsconfig.json shouldn’t be used as build configuration. But it is because MS is usingtsc
as a linter that this issue is a problem for us.Real-world example:
/tsconfig.json
/src/**/*.ts
/src/**/*.spec.ts
/tsconfig.json
obviously excludes*.spec.ts
so they aren’t compiled into/lib
and distributed to npm.something.spec.ts
uses decorators (mocha-typescript
) - VSCode gives many “Experimental support for decorators is a feature that is subject…”We will not put our tests in a separate
/tests
folder because they are not visible. When specs are beside the files they’re testing, it is easy to see when tests are missing or haven’t been updated. So with the spec files in the same folder as the source code, how exactly would one go about telling tsc/VSCode that there are different requirements for spec files?I have tried putting a spec-specific
tsconfig.json
in the/src/
folder and leaving the maintsconfig.json
in the root. That didn’t work.I can see that this isn’t necessarily a typescript issue - for me it’s more of a VS Code configuration issue - I should be able to specify which
tsconfig
matches which files - but I think the request here is that it “just work” because the files themselves already have the matchers needed to decide which config to use. There would just need to be some way to register all the config files or some naming convention, etc.I’m more in favor of a VSCode config file that would register my two
tsconfig.json
files and based on the include/exclude settings in the file choose the proper config to pass to tsc for the file I’m looking at.I don’t have the perfect solution, but I know that putting things like this at the top of all my spec files:
shouldn’t be necessary. And looking at this makes the problems panel in VS Code useless.
extends works for maintaining multiple build files, but there’s still an editor issue. Jetbrains (IntelliJ / WebStorm) recently implemented IDE support for selecting the appropriate tsconfig file by exclude / include / files: see the blog post and bug
A rough description, they have configurable file name patterns for config files, expanding the lookup for
tsconfig.json
(say, totsconfig.*.json
- it seems they reverted the default pattern list since the post to justtsconfig.json
again), and for each edited file select the first found config where the paths match.Therefore, you could have, for example:
tsconfig-base.json
with common settings (not directly used)tsconfig.web.json
withlib: ['dom'], types: []
andinclude: ['src'], exclude: ['*.test.ts', '**/__mocks__']
tsconfig.test.json
withtypes: ['node', 'jest']
andinclude: ['src/**/*.test.ts', 'src/**/__mocks__']
tsconfig.scripts.json
withtypes: ['node']
andexclude: ['node_modules', 'src']
And have the editor know that, e.g.
describe()
is invalid inscripts/start.ts
, andwindow.location
is invalid insrc/App.test.ts
Is there any option of rethinking this?