DEV Community

Discussion on: Tossing TypeScript

Collapse
 
ecyrbe profile image
ecyrbe • Edited

Hi Adam,

I know you wrote this article some time ago now, i just wanted to share with you what i use typescript for.

First i completely agree, typescript is not the answer to all runtime issues we face when using javascript.

Like you said it can make you too confortable about your code if you don't ckeck your external data, and then when feeding it live with bad data all this comfortable dream goes away!

But like a lot of programmers, i'm lazy, i don't want to do defensive programming in all my code. So what i do is :

  • use typescript as code completion utility.
  • use typescript to make type checking sound asuming i'm feeding correct data to my program.
  • use data validation from any external data input to not make this typescript dream go away (i use ajv or hapi joi to validate everything) :
    • user data (forms) validation
    • data transfert objects (dto) validations
    • api result data validation
    • localstorage validation
    • database data validation (when using mongo)
    • cache validation
    • config file validation
  • ban any type, prefer generics and when generics don't apply use unknown or Record<string,unknown> or unknown[].

All this comes at a cost that not everybody wants to pay. But for me and my team it works. We are now using typescript for 2 years and we are now really efficient with it and this workflow.

Collapse
 
bytebodger profile image
Adam Nathaniel Davis • Edited

First, a sincere "Thanks!" for the feedback. It's appreciated. And, for the most part, I think I actually agree with everything you've written here.

I've been "slinging code" long enough now that I can (usually) assess, fairly quickly, the relative strengths-and-weaknesses of any given approach. Specifically, with regard to TS, I definitely don't disagree with the benefits you've outlined here.

In fact, another senior member of our team spoke up a month-or-so ago and said, "Guys... why are we going down the TS path???" And when he did, I pointed out code-completion as a major benefit. I use JetBrains/WebStorm, and I find their code-completion to be awesome - even for non-TS projects. But I will freely admit that the code completion is even better when I use it for TS projects.

That being said, part of my inspiration for writing this article was that, in the final analysis, I just didn't find these "benefits" to be worth the cost. To be absolutely crystal clear, I'm NOT saying that the benefits aren't there. And I'm not asking, at all, for you or anyone else to agree with my analysis. But for me, the benefit... just, isn't, there.

I will also outline one last point here: I've come to accept the fact that, a lot of TS's supposed-benefits are probably things that I've kinda figured out how to "fix" in my own vanilla-JS dev. And I'll freely admit that, in most teams, you can't assume that most of your devs are senior enough to have figured out those things on their own. So... on "most" teams, maybe TS is a far better option. I can freely acknowledge this. But for me.... it just feels like an unnecessary burden.

But... that's just a lotta opinion from me...