TypeScript + NodeJS

・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)
 

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

 

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.

 

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.

 

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.

 

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.

 

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.

 

Have you heard of Deno? I've played around with node for a while now, and created some services using express/mongoose along with mongoDb, not had the opportunity to work with it professionally yet outside of some unit testing.

However from what I understand is that Deno a TypeScript runtime from the creator of Node. Worth a checkout. But honestly more organizations are still probably using Node and will be in the future for a while. I think if you have a solid understanding of JavaScript and can write clean code in Vanilla JavaScript, don't worry about trying to learn something like Typescript for portfolio purposes.

With that said. I love TypeScript for the strong typings it offers and the OOP feel that doesn't come with poorly written JavaScript. My two cents.

 

Definitely worthwhile to learn. Typescript is a great language.

Classic DEV Post from Feb 8

Life Can Be Tough, But We Are DAMN Good at What We Do!

We are problem solvers, thinkers, tinkers, and dreamers. Personal challenges, no matter how severe, can NEVER take that away

Anderson. J
Systems engineering student. Full Stack Developer 👽
Sign In

Follow the languages and libraries you care about.

Happy coding ❤️