A
A
Al2016-06-01 13:07:18
JavaScript
Al, 2016-06-01 13:07:18

Is it possible to write in TypeScript under NodeJS?

The question is, is this a good practice? Will I be able to use npm packages without any problems, or some third-party scripts/classes written in js?
I need all the pros and cons of this approach, I want to know whether it is worth starting a nodejs project on ts, or limiting myself to es6.
ps I read that in ts 1.8 there is some kind of thing that adapts any code without much effort, but I don’t know how effective it is

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2016-06-01
@Sanu0074

Is it possible to write in TypeScript under NodeJS? The question is, is this a good practice?

Yes Yes
If you figure out what .d.ts files are for and how to use typings, then there will be no problems.
Pros:
- fresh features from the ES specs
- static typing, and, therefore, all the advantages that it gives. in a nutshell: some errors will be caught even before launch and, accordingly, fewer tests are needed
- good language support by all sorts of editors. Jetbrains IDEs will be better at giving hints. And even simple code editors like Atom, Sublime, VS Code will start giving normal tooltips, stepping through definitions in code, giving method signatures, and so on.
Cons:
- You need to understand how to correctly connect regular js libraries to the project. In general, it is not difficult, but many do not master it.
- Types "exist" only at compile-time. The output is plain JS with all its dynamic nature. If the code is poorly written (for example, the type any is often used), then typescript will not help.
And I already spoke about debugging: there are no problems with it. You just need to connect this thing here , and everything will be fine. VS Code definitely knows how to connect to the node (and chrome) debugger and will jump on the sources, and not on the compiled mess.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question