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?

Oldest comments (60)

Collapse
 
jay8142 profile image
Sir Broddock

My recommendation would be to not let it slow you down. Make good use of the typescript config file, ensuring that the strictness is calibrated to the level you need. It's phenomenally productive to catch sneaky bugs at compile time, even if it may not seem that way on the front leg of dev.

The awesome thing about the ts-config compiler options is that you can scale them up over time. The goal is to have full strictness enforced, but if and when that slows you down then by all means dial it back. The goal is DX and developer productivity, it just so happens that specifying types at compile time do allow for huge amounts of preventative measures

Collapse
 
psypher1 profile image
James 'Dante' Midzi

See, no one ever mentioned this to me - that I can choose how I want to work.

I will look into making it work for me and not the other way around.

This makes more sense

Collapse
 
peerreynders profile image
peerreynders • Edited

I'm not particularly fond of TypeScript - overall I view it as having poor ROI but decided to learn it anyway so that I could at least have a somewhat coherent base to criticize it from.

That said I accidentally fell into an interesting work flow. I was trying to use uvu with TypeScript. It uses tsm to test TypeScript code.

With that setup you can actually focus entirely on getting your unit tests done first without paying any attention to TypeScript - type checking (linting) only occasionally when the test results don't make any sense (i.e. overall the tests where more effective pointing out issues than TypeScript).

Once you're done with a unit of work you can then focus on what TypeScript is complaining about - "oh yeah, I better clean that up".

That allows a "JavaScript style" work flow with (a sprinkling of) explicit TypeScript types for documentation.

Basically use fast non-checking transpilation with a fast loader for reqular work and only run the full type check at the end or when things get weird.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

This is realty interesting... Is there a public repo I can look at?

Thread Thread
 
peerreynders profile image
peerreynders • Edited

Not sure what you are hoping to find but recently I put together solid-hackernews-a.

Vite uses esbuild for "discarding type annotations" - so npm run dev doesn't type check (presumably that is supposed to happen a priori in the IDE/language server enabled editor). npm run lint:types is used separately for static type checking.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

Not looking to find anything specific. I understand technologies better by having a look at how people use them over reading the docs...

I'll have a look, thank you

Collapse
 
tqbit profile image
tq-bit • Edited

"why must I use it?"

You don't have to, but I think you'll learn a lot if you do.
^this

All I can do is to promise you'll thank every developer (including your past self) if they write their code with static types.

Don't like TS for typing? Maybe you'll prefer JSDoc: typescriptlang.org/docs/handbook/j...

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Granted, I could have chosen better wording. Most of the times I come across people hyping TS it's usually "it'll make you faster". The way I work, fast is not a metric I focus on. But using that, I have spent more time doing something in typescript than I would have if It were just JavaScript.

It's not that I don't like it, I'm just not convinced more than anything. JSDoc you say, I'll have a look at it .

Thank you

Collapse
 
tqbit profile image
tq-bit

Most of the times I come across people hyping TS it's usually "it'll make you faster"

The thing here is - it does make you faster on 'common' development projects. This implies, you:

  • work in a team
  • have a dev workflow including code review, exhaustive testing, and so forth
  • re-write a bunch of features in each sprint phase

I think not being convinced is okay. My portfolio is written in JS as well. And I see no good reason to rewrite it just for the sake of adding Typescript to the codebase. The last two hackathons on dev.to, I wrote using Typescript. I didn't work on them regularly. Since they use several layers of abstraction, VSCode's TS intellisense was really helpful to understand

  • function / method argument types
  • return value types
  • how to instantiate a class
  • getters from Pinia

That's what I meant about the "you'll thank every developer later" part. The less mental capacity you use memorising what you built earlier, the easier it is to plan what to write next. Or whether you can re-use or refactor your modules.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

This makes sense. When I do work on a project that uses it, then I'll dedicate more time to. As of now, I don't have a valid reason...

The whole affair drove me to build the portfolio with Eleventy instead - to actually see what javascript is necessary for it. For that, I'm grateful

Thread Thread
 
peerreynders profile image
peerreynders • Edited

Last time I checked there were additional hurdles to using TypeScript with 11ty.

Enough for me to consider using Astro instead if TypeScript was a critical consideration.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

Oh no, Eleventy was after... I was initially building in Next.js with TS..

Then the TS thing made me decide to forgo frameworks altogether

Collapse
 
peerreynders profile image
peerreynders

I like the idea of JS Doc TS but in my judgement you have to be good with TypeScript first before trying to tackle JS Doc TS (and it has an even larger hurdle for initial setup). The best JS Doc TS example I know of is Preact.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

Oh boy....

Collapse
 
grantdotdev profile image
Grant Riordan

Once you get the "hang of it" you won't be battling with it. It will become second nature to build variables and type them.

By doing so you won't see as many type errors and such. It's just a learning curve. Persevere and you will seen the benefits !

Collapse
 
psypher1 profile image
James 'Dante' Midzi

I'll keep at it, without a doubt... I wanted to hear what other people say about it

Thank you

Collapse
 
curiousdev profile image
CuriousDev

You do not "have to" use it. You would use it, because from what it offers on top of JavaScript you could think it is worth it. There is no need to use it, because you "have to". Typescript bascially is just an extension of JavaScript and allows you to use strict typing, which would make it comparable to lanuages like C#. Editors can make use of it and make development easier (show you allowed methods etc.) as well as allow you to integrate these types as a kind of "rules", which will lead to code, which does not get built, if you break these "rules". There would be no error during the execution in this specific cases, if you could not use it this way. If you want to use some of these points, which I just have described, for your project, you can see them as a must.
But you are not forced to used it and if you are still learning JavaScript, then stick to it for some time before you add with TypeScript to the language's complexity (my opinion at the moment).

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Yeah, I'm noticing my wording could have been better (writing while tired)

My question was more on the "why" I see a number people advocating the switch to it. My question comes as my JS is solid enough to do what I need, so why would consider adding TS to the mix is all

Thank you for the elaboraion.

Collapse
 
curiousdev profile image
CuriousDev

But I am also sorry, if my answer has been too serious. Thanks for your kind response.

Thread Thread
 
psypher1 profile image
James 'Dante' Midzi

It's alright... I got your thoughts as well as valuable information - which was my intention.

Collapse
 
wjk22 profile image
Wojtek Kalka

Hey learn brainf***, teaches you something .. there is nothing you have to, but code is just a lot nicer to read and you can avoid some bugs easy ..

Collapse
 
eshimischi profile image
eshimischi • Edited

Typescript is simply the same Javascript but extended with typing, but not only that. You’ll become better JS dev, with the full picture of this technology whether you use it widely or not, OOP, style of coding, tests, security, new features (ES2022..) and etc.

Collapse
 
mistval profile image
Randall

TypeScript has a fairly large learning curve (I would say larger than some real statically typed languages like C# and Java) and it WILL slow you down on small projects. It's also easy to use TypeScript poorly, and not get much benefit out of it, if you just throw any at any sign of a problem.

But when you get into large projects, especially when you're working with other people, it will accelerate you and make your code better (if you use it well, anyway). Refactoring gets much easier, intellisense gets much better, you know what kind of data you're working with.

Some people are all-in on TypeScript and use it for everything. I'm not one of them - I find it a waste of time for relatively small, personal projects. But I'd never consider using plain JavaScript for anything substantial anymore.

Collapse
 
psypher1 profile image
James 'Dante' Midzi

Oh yes the any thing was the first thing I took to heart when i watched Jack Herrington's series. To that effect, i understand not to throw any everywhere

This is understandable, thank you for the explanation

Collapse
 
matthewbdaly profile image
Matthew Daly

Adding types to your code in general is tremendously helpful when working on larger projects, regardless of the language. I've found static analysis tools like Psalm incredibly useful in PHP as well - it's found an awful lot of problems in legacy code.

There's a few options for adding types to JavaScript and while I have used Flow in the past, and still prefer it conceptually to the idea of a whole new language, the tool support is significantly better in Typescript. There are some things Flow does better (opaque types are frustratingly still not a thing in Typescript), but overall Typescript is the better experience.

 
psypher1 profile image
James 'Dante' Midzi

To make sure we wouldn't catch up to them 😂😂😂

Collapse
 
stephyswe profile image
Stephanie • Edited

Dont use TypeScript unless you know how to use it. When you do some lessons / courses and can use it fluidly to create apps. Then you know why you use it.

TypeScript is absolutely essential in coding. As you secure the flow in your app. What you gain with TypeScript? Debug time is lowered immensely. As you cannot basically make big errors.

Collapse
 
cjsmocjsmo profile image
Charlie J Smotherman

Websites/Javacript ran just fine well before typescript came along, so the notion of typescript being "absolutely essential in coding" is questionable.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
k_penguin_sato profile image
K-Sato

If you are just making small web applicatins or wrting simple scripts, JS is all you need.

Collapse
 
jwp profile image
John Peters

Seems like there are two camps 1. The haters and 2. The lovers of TypeScript.

I'm a lover of it for one major reason Intellisense. Ok two reasons, compile time errors instead of runtime errors.

Runtime errors and lack of intellsense are prehistoric.

Collapse
 
localpath profile image
Garrick Crouch

Refactoring is a breeze and it'll help catch dumb mistakes that you will see no matter what after bundling so in that sense it can save time or make you a more efficient developer. I personally hate that we rely on transpilers but it's an implementation detail for now. Hopefully we'll get static typing in JS and TS can go away.

The setup is actually easy if you study the TS rules for the compiler, don't take it in all at once, there's so much utility to it. Plus you get to incrementally upgrade your project to TS so it's not an all or nothing.

Collapse
 
wjk22 profile image
Wojtek Kalka

Great minds discuss ideas; average minds discuss events; small minds discuss people