How to use multiple tsconfig files?

I use Visual Studio Code and have a fairly general project structure:

โ”œโ”€โ”€ client/ โ”‚ โ”œโ”€โ”€ tsconfig.json โ”œโ”€โ”€ shared/ โ”œโ”€โ”€ server/ โ”‚ โ”œโ”€โ”€ tsconfig.json โ”œโ”€โ”€ project.json 

Two tsconfig files have different settings (for example, under client/ target ES5, then under server/ target ES6).

The problem is that I want the shared directory to be included in both projects. I cannot do this with tsconfig because the exclude parameter will not allow me to include a folder that is in a higher directory than tsconfig.json, and using files , I have to keep the list of files permanently until it does not support globes.

Note that I can compile everything by adding a shared folder to tsc, I want the Visual Studio Code IDE to recognize the common code for intellisense, etc.

The only way to wait for filesGlob ?

+19
source share
5 answers

The new version of VSCode supports Typescript 2, adds adds globs support to tsconfig.json with the include option. See http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

+1
source

I answered this here: tsconfig extension answer

The essence of the answer:

You can do this by expanding your base tsconfig.json file:

tsconfig extension

just donโ€™t exclude directories in the base tsconfig.json file, and typScript should be able to resolve your sets for you (know that this is the case using node_modules / @ types or the typings module)

For instance:

configs /base.json:

 { "compilerOptions": { "noImplicitAny": true, "strictNullChecks": true } } 

tsconfig.json:

 { "extends": "./configs/base", "files": [ "main.ts", "supplemental.ts" ] } 

tsconfig.nostrictnull.json:

 { "extends": "./tsconfig", "compilerOptions": { "strictNullChecks": false } } 
+9
source

The only option to wait for glob files?

The best option:

  • Just use a single tsconfig.json And only the package (using something like webpack) files in the client (webpack will take links to general ones).

This is the workflow that I use here https://github.com/alm-tools/alm ๐ŸŒน (the only tsconfig.json https://github.com/alm-tools/alm/blob/master/src/tsconfig.json )

This workflow is also covered in alm design documents: https://basarat.gitbooks.io/alm/content/contributing/

+1
source

Use one tsconfig.json for root. And then expand it for each project ( tsconfig.server.json backend, tsconfig.webpack.json interface).

  • The root tsconfig.json include: ['src'] to ensure that all files are typed in the IDE.
  • tsconfig.server.json exclude: ['src/app'] interface tsconfig.server.json files
  • tsconfig.webpack.json : tsconfig.webpack.json exclude: ['src/backend'] backend files

More

Lesson example

0
source

as another option to associate the npm command with the next run

 { 'start': '...', 'buildFront': 'tsc -p tsconfig.someName.josn' } 
-one
source

All Articles