Ts-node: Support tsconfig.json extending (via extends property)

Created on 28 Dec 2016  Â·  9Comments  Â·  Source: TypeStrong/ts-node

Also called "Configuration inheritance". It doesn't work now

bug

Most helpful comment

So considering the fact that all the options minus those two pre-defined defaults need to be used anyway, I opted to just pull those two options out and set them after I parse the content. It should be patched with https://github.com/TypeStrong/ts-node/commit/ec00796677744f3ee60212e14abb0abb69a64218 now.

All 9 comments

And it worked before?

This is unlikely to be an issue with ts-node if it worked before. Please check your TypeScript version to make sure the version being used supports the feature. This feature exists purely on TypeScript's side.

@blakeembrey
It didn't work before, because it's new feature of TS 2.1
I use ts-node 1.7.3 and typescript 2.1.4.

Really? It works fine for me without any changes.

@blakeembrey
I create a little example.
In terminal it's without errors:

./node_modules/.bin/tsc -p ./src --noEmit
./node_modules/.bin/tsc -p ./test --noEmit
./node_modules/.bin/ts-node -P ./src ./src/1.ts

But:

./node_modules/.bin/ts-node -P ./test ./test/2.ts

TSError: ⨯ Unable to compile TypeScript
Cannot find global type 'Promise'. (2318)
src/1.ts (1,16): An async function or method must return a 'Promise'. Make sure you have a declaration for 'Promise' or include 'ES2015' in your `--lib
` option. (2697)
    at getOutput (/Users/arusakov/WebstormProjects/upvista/ts-node-repro/node_modules/ts-node/src/index.ts:312:17)
    at /Users/arusakov/WebstormProjects/upvista/ts-node-repro/node_modules/ts-node/src/index.ts:343:18
    at Object.compile (/Users/arusakov/WebstormProjects/upvista/ts-node-repro/node_modules/ts-node/src/index.ts:502:17)
    at Module.m._compile (/Users/arusakov/WebstormProjects/upvista/ts-node-repro/node_modules/ts-node/src/index.ts:406:44)
    at Module._extensions..js (module.js:580:10)
    at Object.require.extensions.(anonymous function) [as .ts] (/Users/arusakov/WebstormProjects/upvista/ts-node-repro/node_modules/ts-node/src/index.t
s:409:12)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)

I can provide any additional info or help with this.

Ah, I see. This isn't an issue with extends, it does work. But it appears that the default configuration we merge is prioritised over extends, which makes sense - https://github.com/TypeStrong/ts-node/blob/b2e6990783b6a3bb6fc52d101e625f0a6f6d8861/src/index.ts#L419-L434. I'm not sure on the correct solution as we need to merge those options as some point.

@blakeembrey Thank you, it's clear. We can't reorder merge arguments, why?

@Vishal-Isharani If you're after support, please create a separate issue or read the existing thread. Your comment is unrelated and doesn't add anything to the existing discussion.

@arusakov We can definitely move them so that we merge _after_ TypeScript parses them, but I'd need to find the correct TypeScript method for TypeScript to turn the passed in compiler options into their corresponding enum codes. I guess we just parse twice? If you think it's the right approach, happy to make the change and will definitely accept a PR!

So considering the fact that all the options minus those two pre-defined defaults need to be used anyway, I opted to just pull those two options out and set them after I parse the content. It should be patched with https://github.com/TypeStrong/ts-node/commit/ec00796677744f3ee60212e14abb0abb69a64218 now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dakom picture dakom  Â·  3Comments

sanex3339 picture sanex3339  Â·  4Comments

nehalist picture nehalist  Â·  3Comments

huan picture huan  Â·  3Comments

max-block picture max-block  Â·  4Comments