In TypeScript, when you have multiple tsconfig.json files in a project, the child tsconfig.json does not directly override the properties defined in the parent tsconfig.json. Instead, it extends the configuration from the parent, allowing you to add or override certain properties for the specific module.

Here's how the extends property works in tsconfig.json:

  1. The child tsconfig.json file extends the settings from the parent tsconfig.json using the extends property.
  2. It can then add or override specific properties in the child tsconfig.json.

For example, suppose you have a project structure like this:

lua
project/ |-- tsconfig.json (Parent) |-- module/ | |-- tsconfig.json (Child) | |-- src/ | |-- ...

In this scenario, the tsconfig.json in the module/ folder can extend the settings from the parent tsconfig.json in the root of the project. Here's how you can set it up:

  1. tsconfig.json (Parent):
json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "outDir": "dist" // Other common compiler options... }, "include": ["src"] }
  1. module/tsconfig.json (Child):
json
{ "extends": "../tsconfig.json", // Relative path to the parent tsconfig.json "compilerOptions": { "module": "es2020", // Override the module setting for this module "outDir": "dist/module" // Override the output directory for this module // Other specific compiler options for this module... }, "include": ["src"] }

With this setup, the child tsconfig.json in the module/ folder will inherit the settings from the parent tsconfig.json, and you can override specific properties like module and outDir for this module.

When you run TypeScript compilation from the root of the project, TypeScript will use the child tsconfig.json in the module/ folder, and it will take into account the extended settings from the parent configuration.

If you are experiencing issues where the child tsconfig.json does not seem to be inheriting from the parent, ensure that the file paths and extends property in the child tsconfig.json are correct. Double-check the paths and verify that there are no typos or mistakes in the configuration files. Also, make sure you are running the TypeScript compiler from the root of the project to use the correct configuration.

Have questions or queries?
Get in Touch