Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ts-node regardless of errors?

I've got some trouble with ts-node when I develop.

I want to test something, so as you know, comment is my best friend. But with ts-node I've got this error :

'foo' is declared but its value is never read

But I don't want to comment all my unused variables because theses variables are in fact useful for the code after testing.

So, is there a solution like ts-node --please-let-me-work to ignore these error ?

Thanks ;)

like image 275
La Gregance Avatar asked Mar 17 '20 16:03

La Gregance


People also ask

Can I use ts-node in production?

No you shouldn't use it in production, even though it will cache the compiled files it'll be slower to start and consume more memory because it keeps around an instance of the compiler and files in memory.

Does ts-node need Tsconfig?

Default config​ If no tsconfig. json is loaded from disk, ts-node will use the newest recommended defaults from @tsconfig/bases compatible with your node and typescript versions. With the latest node and typescript , this is @tsconfig/node16 . Older versions of typescript are incompatible with @tsconfig/node16 .

Does ts-node require TypeScript?

ts-node is an npm package which allows the user to run typescript files directly, without the need for precompilation using tsc . It also provides REPL. ts-node does not bundle typescript compiler, so you might need to install it.


2 Answers

ts-node has a --transpile-only (or -T) argument. It will ignore all type errors and just build your project.

My 2022 suggestion for this to set up esbuild instead. Not a plug and play experience, but extremely fast. We use esbuild for (constant) building during development, and rely on other tools to report type errors.

like image 106
Evert Avatar answered Oct 13 '22 01:10

Evert


If you use ts-node, you can use this alternative :

$ ts-node-transpile-only filename.ts

It will run the typescript file without checking errors.

like image 25
justcodin Avatar answered Oct 13 '22 02:10

justcodin