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!
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!
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
.jsfiles directly (usually just usets-nodefor tests and development).