tsconfig icon indicating copy to clipboard operation
tsconfig copied to clipboard

Support tsconfig inheritance

Open danielmoore opened this issue 9 years ago • 10 comments

As of TS 2.1, there is now an extends field that allows configs to inherit configuration from other files. It'd be great if this library emulated that behavior (though perhaps it should be configurable)

danielmoore avatar Jan 11 '17 19:01 danielmoore

You're welcome to submit a PR, but I'm not sure I'll be implementing it myself here. If you need this, it's probably best to parse the tsconfig.json file using TypeScript to avoid additional changes in the future.

blakeembrey avatar Jan 11 '17 19:01 blakeembrey

If anyone's interested, I implemented support for extends in the grunt-ts tsconfig feature. The code to do so was fairly minimal, though I do have a dependency on underscore.

https://github.com/TypeStrong/grunt-ts/pull/398

nycdotnet avatar Mar 28 '17 20:03 nycdotnet

I've made a PR #27 which handles "extends" (multiple too).

@blakeembrey at the moment i "just" wrote a little merge function for this behavior cause if we use the typescript api we could rewrite a bit more than i did.

Zerogiven avatar Jan 05 '18 05:01 Zerogiven

it's probably best to parse the tsconfig.json file using TypeScript to avoid additional changes in the future

I would be grateful to you if you can provide some docs, because I can't find it and ts codebase is too huge and difficult to search into.

And one more question

it's probably best ... using TypeScript to avoid additional changes in the future

So what is this library for? (no irony or gibe). In my opinion any manipulations with tsconfig.json should be done using TS to avoid additional changes in the future

rifler avatar Apr 27 '18 04:04 rifler

@rifler Legacy. It used to be required because TypeScript didn't expose the features needed. It could still be used by people that want to load tsconfig.json files but don't want to include the entire TypeScript compiler. You can reference https://github.com/TypeStrong/ts-node if you'd like, it parses the file (there's a few different methods for slightly varying things, I had to read through the TypeScript codebase myself).

blakeembrey avatar Apr 27 '18 11:04 blakeembrey

Awesome, thank you so much, you save me a lot of time.

rifler avatar May 07 '18 17:05 rifler

@blakeembrey so how does one use the typescript package to load the config in a way that supports inheritance?

ntucker avatar Dec 01 '19 06:12 ntucker

@ntucker You're best diving into the TypeScript package and taking a look. I left a link above to a package I maintain that can help you figure it out (it's not the best way due to legacy APIs in TypeScript).

blakeembrey avatar Dec 01 '19 07:12 blakeembrey

@ntucker Try something like https://github.com/TypeStrong/ts-node/blob/4dbc15dc20da90c0496d117481a7467b6d637cb8/src/index.ts#L631 (not 100% sure from memory if that one method support inheritance, you might need to combine with parseJsonConfigFileContent). I believe there's a short-hand you can use exported by TypeScript that does both in a single function.

blakeembrey avatar Dec 01 '19 07:12 blakeembrey

https://stackoverflow.com/a/53898219/1046439 had the solution. Thanks for pointing me in the right direction @blakeembrey !

ntucker avatar Dec 01 '19 22:12 ntucker