7

I'm working on a project structured like this:

\
|- built
|- src
|- perf
   |- tsconfig.json
|- typings
|- tsconfig.json

My tsconfig.json on the root

"target": "es6",
"outDir": "built",
"rootDir": "./src",

I need a different configuration on the perf folder, like a different target.

"target": "es5",

However, my typings folder is on the root of my project, not inside perf folder. So doing a tsc ./perf results in a lot of errors.

Is there a way to tell TypeScript where to look for typings? I'm using

npm install -g typescript@next
// typescript@1.8.0-dev.20151109

Or a way to have different configurations depending on the folder?

user990423
  • 1,397
  • 2
  • 12
  • 32
BrunoLM
  • 97,872
  • 84
  • 296
  • 452
  • Does this answer your question? [How to use multiple tsconfig files in vs-code?](https://stackoverflow.com/questions/37579969/how-to-use-multiple-tsconfig-files-in-vs-code) – Liam Dec 20 '19 at 08:05
  • Does this answer your question? [how to use multiple tsconfig files (with conflicting compiler options)?](https://stackoverflow.com/questions/61611311/how-to-use-multiple-tsconfig-files-with-conflicting-compiler-options) – Michael Freidgeim Jun 16 '22 at 12:06

2 Answers2

9

you can do this by extending your base tsconfig.json file:

tsconfig extension

just do not exclude directories in the base tsconfig.json and typescript should be able to resolve your typings for you (know this is true using node_modules/@types, or the typings module)

For example:

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
   }
}
weagle08
  • 1,763
  • 1
  • 18
  • 27
  • 1
    Link-only answers are not useful when the content changes or is removed. Include the relevant parts of the page in your answer, tailored to answer the question. – miken32 Jan 25 '17 at 19:35
  • That is unrecognizable. That means I can't have multiple tsconfigs. – vintprox May 06 '19 at 16:37
1

Is there a way to tell TypeScript where to look for typings

Quickest solution

Move typings into pref.

Long term solution

Use filesGlob once it is supported in tsc : https://github.com/Microsoft/TypeScript/issues/1927

Community
  • 1
  • 1
basarat
  • 261,912
  • 58
  • 460
  • 511