DEV Community

loading...

TypeScript + NodeJS

Anderson. J
Estudiante de ingeniería Back End Developer 👽
・1 min read

Hello people! How many of you are using TypeScript in backend?. It worth?
I'm getting more confidence with JS and i've read a lot about Javascripts supersets that can support static type check and brings the real OOP paradigm. I think is great, I have some experience with CPP so I have a decently OOP background. But it really worths learn it? I'm actually working in smalls projects to build a freelance portfolio and I'm not sure if TS could produce additional value to my development.

Discussion (8)

Collapse
pavelsevcik profile image
pavelsevcik

From my perspective is TypeScript utmostly about "higher" productivity.

TypeScript itself is just "JavaScript that scales", and "starts from the same syntax and semantics that millions of JavaScript developers know today".

Where it highly starts paying off is when you leverage on the synergy of TypeScript with development tools with integrated support of TypeScript. You'll get tools like

No need to take just my word for it, check others too

We love TypeScript for many things… With TypeScript, several of our team members have said things like 'I now actually understand most of our own code!' because they can easily traverse it and understand relationships much better. And we’ve found several bugs via TypeScript’s checks.”

— Brad Green, Engineering Director - AngularJS

Collapse
lucretius profile image
Robert Lippens

I started exclusively using TypeScript in all of my new projects starting a few months ago and haven't wanted to look back since. I always set the strict flag to ensure I get the most type checking possible. It is true that this makes things a... pain sometimes (and I will occasionally find myself reaching for the easy way out of using "any") but I find it helpful much more often than not.

You also can use something like ts-node to run your serverside code. Yes, it has to initially compile things before starting but then I believe the result is cached - for a long running server I don't think this is an issue but start times for something like a lambda function could be problematic. Even in this case, all you need to do is compile your typescript and run the bundle.

Collapse
whoisryosuke profile image
Ryosuke

I too recently got bit by the Typescript bug and I'm incredibly interested in the prospect of bringing type checking to Javascript. I'm so used to doing it in PHP, I'm amazed that JS doesn't have it built in.

If you're working with smaller projects I don't think it's really worth it. Any benefits you'd get from type checking can be gained through efficient unit tests. Type checking is more important for large-scale projects, or building flexible/reliable modules. If you were designing components for design systems, utility methods, APIs, etc -- I'd recommend it.

Collapse
stereobooster profile image
stereobooster • Edited

Any benefits you'd get from type checking can be gained through efficient unit tests.

Well, not quite. There is some difference in those approaches. Imagine all possible bugs in our system as a big flat area. Types can cover the whole regions of the area preventing, not one exact occurrence, but the whole class of some errors. Tests, on the other hand, prevent only some exact bugs (which developer think of and write tests for).

Than types are better? Not quite. Static type system can cover only some class of errors, but not all of them. There are some techniques and more advanced type systems which can cover bigger number of errors. Meantime I recommend to use both.

You can read more in my post.

On original post: downside of TS on the server-side is that you will need compilation step and it will be one more thing which needs configuration.

Collapse
gameoverwill profile image
Wilfredo Pérez

Adding some words or ideas Typescript helps you to organize your code because it's strongly typed. In fact, nowadays I have changed a lot micro services that I did with vanilla javascript to typescript and the code is clean and beauty. Beside, the Code review is much easier and we know what mistakes we can look for inside the code.

From my point of view and is the same that other people said, It's worth.

Collapse
pojntfx profile image
Felix Pojtinger

I'm using TypeScript to develop LibreSat, and it's awesome. It gives JS the scalability that it has always missed IMHO (I have to write less tests, basically) and when used in conjunction with Parcel etc. it's zero-config.