DEV Community 👩‍💻👨‍💻

Cover image for Sell Me On Typescript
James 'Dante' Midzi
James 'Dante' Midzi

Posted on

Sell Me On Typescript

I'm a Python developer and this strictly typed langauges this something I left after I finished my Diploma (C, C++, Java)

I later got into React and all those web dev stuffs that the kids are into. At that time javascript was all you really needed. Then the wave of Typescript hit and everyone jumped on.

I get all the "advantages" of it, but in the past few months I looked into it and decided to rebuild my portfolio with it - the portfolio is still not done.

Most of my time was spent making Typescript happy and not building.

So, you Typescript pundits, why must I use it?

Latest comments (71)

Collapse
 
ikfreecharles profile image
Ikfreecharles

A big advantage of TS is the way it helps you check logic errors you won't catch using only Js. A lot of times, I don't even bother writing tests for these, cause well, TS done most of the checking for me indirectly. Working in a team, TS helps to prevent a lot of programming error types also. Even if these are the only two merits, it's totally worth it for me.

Collapse
 
dannystyleart profile image
Dániel Sebestyén

IMHO TS itself does nothing else then clears a bit of context of our code.
If you don't know js but came from any other strongly typed language, it helps you to understand what's going on with typeflow - assuming the project is properly typed - and gives you some insights of the surroundings, like it's typed for node or browser env.
But to really make code that is efficient and consumable, discoverable you still have to understand javascript, since it is just a superset of it.

Collapse
 
johnb8005 profile image
John B

I moved to TS about 3 years ago. I never looked back.

The ability to work in a pseudo typesafe environment is an absolute game changer and will make your code more robust and easier to iterate on.

It will also force you to do more "engineering" vs simple dev. Needless to mention that I would write many tests which have now become obsolete.

Collapse
 
anujssstw profile image
Anuj Singh

for frontend, i don't think it requires that much of types except when you are passing different data throughout the components and for the back end it becomes incredibly useful when you are able to look up what you need to pass and in which format

Collapse
 
anujssstw profile image
Anuj Singh

nice jucie auto complition

Collapse
 
jwhenry3 profile image
Justin Henry

My argument for typescript has 2 parts:

  • intellisense benefits from the definitions as you write them, and it paints a picture for other developers that come before you (though I know jsdoc can do this as well, it is easier for developers used to strictly typed languages to adapt)
  • many of the features of typescript come out long before javascript adopts them, so it has a great track record of predicting what javascript will do. Having a head start on newer patterns gives you an advantage when the world eventually phases out typescript and leaning into most of its features.

My own personal reasons for using typescript involve being able to be self-accountable and make sure all the contracts I write with the code are properly handled. It can give you some freedom when writing internal code, so you don't need to necessarily write tons of runtime checks on the data since you know the compiler will check for a lot of that. The only areas where data checking is really important in typescript is when you have an external data source (or input) that could come in during runtime that can possibly not meet the structure contract. As you adapt to the nuances of the flavored language, it gets easier and faster to build.

The biggest evidence of your struggle not being with the language is that the code you write does not obey the rules you write, so its more of an issue of how you are writing the code, not with typescript itself. Think of it like training wheels. Eventually with enough coding in typescript, writing a specific way will become second nature and you can take those practices with you into JavaScript.

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Contacts? Web3?

I'm not foreign to typed languages, Typescript has just given me more grief than the other ones.

I wanted to understand the increasing adoption of it

Collapse
 
jwhenry3 profile image
Justin Henry

For many, the fact that javascript isn't typed keeps people from working on web projects, and typescript was a way to bridge that gap. Being that it was developed by Microsoft, perhaps it was developed to bridge the gap between C# and web so they could reuse developers from backend on frontend to a degree, for familiarity.

Collapse
 
jackmellis profile image
Jack • Edited on

The cost of learning and applying typescript is quite high. It will slow you down at first.
The main early benefit is type safety and intellisense. But it often feels like it's a lot of work for little gain.
But in my experience, you reach a point where you suddenly find yourself moving much faster, having way more confidence, and then you'll join another codebase in javascript and you'll realise how much you lose when you don't use static typing.

Collapse
 
chiefgui profile image
Guilherme Oderdenge

I am a die hard TypeScript fan. But not because of TypeScript; I am a die hard fan of it because of types.

At first, it will definitely slow you down. The equation is simple: if you start writing Rust now, you'd be way less productive than you are with Python, for instance. That's not exclusive to TypeScript. But once things click in you head, you won't look back.

In the long term, I think types give you more critical thinking on how you code. That means less bugs, greater developer experience, hence better productivity. In the end of the day, TypeScript is something you'll only find value once you really feel it flow.

But in general, I think TypeScript's benefits (or really, static types benefits) can be summarized to:

  • Greater Developer Experience,
  • You'll be more confident to scale your app,
  • You'll be more productivity to model your projects all around.

That said, I'd say TypeScript is far from being required for small projects. Your portfolio, for instance - you definitely don't need it and barely will feel its benefits, regardless of how proficient you are. But if you are willing to scale your portfolio's features, then I'd say it's a great call.

 
psypher1 profile image
James 'Dante' Midzi

This I understand, I had specifc questions in reagrds to Typescript is all

Collapse
 
xowap profile image
Rémy 🤖

Well I don't know.

On one hand I love static typing. In Rust or Kotlin, it takes you by the hand and helps you figure where you are and what you are doing. Very useful.

There is also the case of typing annotations in Python which are super useful for the same reason. I write them all the time and it's no bother at all.

But then when I try TypeScript I feel like I'm fighting against the world. The whole JS world is not built around typing and especially inputs from the API. Taking in all this external data (which let's face it is the largest chance of getting a typing problem) is always super tricky.

On the other hand I'm using Vue and PyCharm, which handles Vue super well so all the auto-complete basically just works without me having to take care of annotating anything.

Not sure what to make of that. JSDoc is indeed probably a better way to go. Getting 99% compliance (JSDoc) is easy but 100% compliance (TS) can be a fucking pain in the ass.

Collapse
 
theaccordance profile image
Joe Mainwaring • Edited on

The primary value-add that I have found with TypeScript is that its features add quality controls to your JavaScript project.

Is it necessary? No, but the value does become evident when an active project scales in complexity and age.

One of my active SaaS products is a Node.js app that started in 2012. Little/no tests, callback hell, and enough features to sell to the enterprise. When I was the team lead on that product’s mobile application, I would have to remediate bugs several times a year when a team member building features for the web modified a shared method and removed/modified an output. If we had types (or tests tbh) around the method’s I/O contract then it would have been caught before merge.

Additionally, callback hell paired with an architecture that IDE’s didn’t fully understand meant significantly more time mapping out process flows within the application. I had to do it a couple times when turnover left me as the one responsible; those efforts took several hours over multiple days, often repeating the exercise multiple times to validate the flow was accurate.

Today, I write all of my application source in TypeScript for new projects if I’m building a JavaScript runtime, but some things like Grunt.js are still authored as regular JavaScript

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Thank you so much for explaining in this much detail. This kind of information is what I was looking for.

This question was shared on Twitter and some of the responses there were discouraging. If i was starting out,I would have given up on it entirely.

Collapse
 
deltd3v profile image
deltd3v

Have you tried typescript yet ?
What was your experience like ?
After trying out typescript by building some toy project, why on earth would you go back to using some awful alternative like flow or even @JSDoc

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Yes, I ask because I have tried it and what I am looking for is more information

Collapse
 
jwp profile image
John Peters

I hear you Brother. I've been told right here on Dev.to that I'm dumb, stupid, illogical, and many other pejoratives. They all were Javascript only purists who even denounced their own language adopting classes. These are the same folks that write 5,000 line mono repos filled with magic strings who don't follow DRY. Talking about insanity.

Collapse
 
cjsmocjsmo profile image
Charlie J Smotherman

And yet there are thousands of Enterprise grade websites out in the wild that don't use typescript. Use if you want to, don't use it, I really don't care, I personally have no use for it (as of now, that may change). Not enough benefit for the cost, I have bigger fish to fry like Rust and Flutter, which I think are a much better investment of my time, but that's me(others may disagree and that's fine). In the end it's nothing more than a personal choice.

Happy Coding

Collapse
 
aktoriukas profile image
Gedi

where do i start...

Making "Typescript happy" is making your code happy & avoiding errors down a line. I can see why that is annoying on a small projects, but when project grows there is no way you gonna avoid errors, and most of them will come from the wrong types, incorrect params and so on... You can avoid all of those ( most of it ) with TS.
Having auto-complete is one of the best feature with TS.

In the end, you don't have to use it. For a small project it may even be noth worth using it. But i thing ones you extensivle use it in one project, there is no going back.

Let's team up together 🤝

We're Hiring

We're hiring for a Senior Full Stack Engineer to join the DEV team. Want the deets? Head here to learn more about who we're looking for.