Typescript: different results if --outDir using relative path is in parent or child tsconfig

Created on 11 Jun 2018  路  6Comments  路  Source: microsoft/TypeScript

Hello,

I don't know if it's intentional or not but given this structure:

* base.tsconfig.json
* aFolder/
      * tsconfig.json (extends base.tsconfig.json)

Actual behavior:
Now running tsc in aFolder:

  • if I have an outDir option in the base.tsconfig.json defined as ./dist it will create the dist folder in the root folder
* base.tsconfig.json
* aFolder/
      * tsconfig.json (extends base.tsconfig.json)
* dist/
  • if I have an outDir option in the aFolder/tsconfig.json defined as ./dist it will create the dist folder under the aFolder
* base.tsconfig.json
* aFolder/
      * tsconfig.json (extends base.tsconfig.json)
      * dist/
  • if I don't specify any outDir files are output in the aFolder folder

Expected behavior:
I would expect the dist folder to be created relatively to the path of the main tsconfig used by typescript (here tsconfig.json) regardless if outDir has been specified in the parent or child tsconfig.json

Working as Intended

Most helpful comment

This is really annoying. apart from other settings I already need to duplicate, I need to duplicate outDir too in all our packages. If only we could use a JavaScript file as config, so we can use cwd if we want to, and other dynamic configuration.

All 6 comments

File paths are relative to the containing tsconfig.jon file location.

@mhegazy thanks for the comment.

I understand, though using the extend keyword I would expect the relative path to be relative to the child tsconfig (as I am "extending" the parent, not "including" it).
The current way means that any configuration that requires relative path will need to be duplicated in all children tsconfig which seems counter intuitive.
Would you know a workaround maybe?

That is a design choice that we made when the feature was first implemented. the rational is files do not really move around, so for path that were originally authored as relative paths, it is strange for these to move around just because the file was used as abase.
The conceptual model to use is that of a class extending a base class, you inherit all the props from the base and you can override them, rather that of a template.

Thanks for your answers :)

I'm having a similar problem, it's there a way that we can use "${cwd}/dist", use an env variable or similar?

This is really annoying. apart from other settings I already need to duplicate, I need to duplicate outDir too in all our packages. If only we could use a JavaScript file as config, so we can use cwd if we want to, and other dynamic configuration.

Was this page helpful?
0 / 5 - 0 ratings