Lewis Fairweather
3 min readJan 11, 2020

--

I agree with you that TypeScript can give developers a false sense of security, but it’s important to know who is at fault for this pattern. Maybe I over-simplified it by saying ‘prevents’ instead of ‘helps to prevent’ or something less black & white. But this article wasn’t about TypeScript so I didn’t think to elaborate. Plus once you learn TypeScript, it becomes clear what is meant by ‘strict typing’.

So…If you have an in-depth understanding of how TypeScript works, then you won’t make the mistake of thinking that it is completely type-safe.

I do think that the development of TypeScript was needed.

It (helps to) prevent one of the most common bugs that are found in vanilla JavaScript — Type Errors, while allowing better hints at other issues along the way as a by-product of strict-typing during development. It doesn’t claim to change the way the underlying JavaScript language works as it all transpiles to JavaScript in the end anyway (which someone who reads the TypeScript documentation would know). At the end of the day it does reduce the likelihood of obvious errors/mistakes. I think having to annotate your code clearly with types etc. gives you a better understanding of data transformations & patterns in your code. There is a bit of a learning curve at first, but it saves time in the long run when you fixing obvious errors that could have been prevented during development.

Developers Mindset

It is the fault of the those developers who turn to TypeScript to magically fix the bugs that are caused by their lack of understanding in JavaScript. These people might feel that it replaces the need to learn JavaScript properly and actually learn the reasons why they have so many runtime bugs in their software. That’s a problem with the mindset of certain developers. I would also argue that if you have this mindset:

  • That you don’t need an in-depth understanding of JavaScript to use TypeScript
  • That you can cut corners as long as ‘it works’
  • That you can fix bugs without knowing WHY it happened in the first place
  • That you don’t need to have a full understanding of the language-specific concepts before writing production code (applicable to any language)

Then maybe you don’t have the right mindset to write code.

You should want to know the why and how of everything you’re writing, you should always be curious to know the inner workings.

Readability

I think that TypeScript is less readable to those who aren’t used to TypeScript.

But isn’t that like every language?

In my opinion, once you are familiar with TypeScript, it becomes more readable as it shows intent more clearly. You don’t have to spend an extra 30 seconds on unfamiliar code figuring out return types & why this function is different from the one above it. You can see the codes’ purpose more quickly if you can clearly see the types for every variable.

You rely less on comments and potential poorly named variables/functions to determine it’s purpose. When I want to get familiar with a TypeScript function, looking at the input types and output types are one of the biggest indicators of it’s purpose for me. Plus all it actually does is describe the JavaScript that you wrote, it should feel pretty intuitive eventually.

But think about it this way…

A junior developer is writing you a demo app that you have to present, but you know he is prone to missing/overlooking the fine details in his code.

Would you be more confident in presenting his app if it was written in JavaScript or TypeScript?

I’d rather he had the errors that TypeScript gives to guide him.

You can’t guarantee that he has a good linter either because there are so subjective configurations.

People that misuse/abuse a language, trying to bulldoze their way to a half working app isn’t specific to TypeScript. That problem is language agnostic.

So what I’m saying is it sounds like you are annoyed at those people who use TypeScript but don’t fully understand it. But these people are everywhere. If they weren’t misunderstanding TypeScript then they would be incorrectly using pointers in C++ or thinking that memory leaks aren’t a thing because you can’t see them.

--

--

Lewis Fairweather
Lewis Fairweather

No responses yet