typescript: extending configs

2020-11-11

 | 

~1 min read

 | 

146 words

In writing about setting Typescript up for new projects, one of the features I discussed in passing is extending configurations. Extending a Typescript configuration is useful in a variety of situations. In the original post, I had a base tsconfig that I would use in development and then extend it with a tsconfig.build.json:

tsconfig.build.json
{
  "extends": "./tsconfig.json",
  "exclude": ["**/*.test.ts"]
}

In this case, our .build config extends a standard tsconfig in the same level of the application (for our purposes, it doesn’t matter what’s included in the config).

Now that we have a configuration that extends another, we can use it specifically in certain circumstances - for example, when we want to actually build the application. Looking at our package.json:

package.json
{
  "scripts": {
    "build": "tsc -p tsconfig.json --emitDeclarationOnly",
    "build:prod": "tsc -p tsconfig.build.json --emitDeclarationOnly"
  }
}

Just like that, we can have multiple configs.



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!