Ts-node: Question: How does ts-node is faster than tsc? What are the trade-offs?

Created on 2 Oct 2018  路  3Comments  路  Source: TypeStrong/ts-node

Hi! I'm very curious on how ts-node achieves faster type check and compilation than tsc, even with local cache disabled (--no-cache). How is this achieved and are there any trade-offs when using ts-node instead of compiling files with tsc?

Thanks in advance for the answer!

question

Most helpful comment

Probably because of the condition mentioned in https://github.com/TypeStrong/ts-node#help-my-types-are-missing. It doesn't use/compile everything by default, but instead starts at a single entry point and spiders out from that. That means you aren't always compiling an entire project, but a subset. Of course, I can't comment on your particular set up for how much that really applies. Everything else is overhead, since it needs to run through node.js runtime also.

There's no major trade-offs that I'm aware of. It really depends on what you want. There will always be a memory overhead for type checking which caches all files. In transpile only mode, there's a smaller overhead since it doesn't need to cache any files but there's still an overhead for source maps in error handling. In both cases it's likely minor for your use-case, though I personally still transpile and deploy .js files directly (usually just use ts-node for tests and development).

All 3 comments

Probably because of the condition mentioned in https://github.com/TypeStrong/ts-node#help-my-types-are-missing. It doesn't use/compile everything by default, but instead starts at a single entry point and spiders out from that. That means you aren't always compiling an entire project, but a subset. Of course, I can't comment on your particular set up for how much that really applies. Everything else is overhead, since it needs to run through node.js runtime also.

There's no major trade-offs that I'm aware of. It really depends on what you want. There will always be a memory overhead for type checking which caches all files. In transpile only mode, there's a smaller overhead since it doesn't need to cache any files but there's still an overhead for source maps in error handling. In both cases it's likely minor for your use-case, though I personally still transpile and deploy .js files directly (usually just use ts-node for tests and development).

Great! Thank you so much for the answer, I really appreciate it!

@blakeembrey this is a GREAT explanation, I encourage you to put this somewhere in the docs!

Was this page helpful?
0 / 5 - 0 ratings