DEV Community

Discussion on: TypeScript is a waste of time. Change my mind.

Collapse
 
ms_35 profile image
ms

Typescript is not a panacea, it's just an extra tool in your toolbox. It's not meant to prevent all problems, just a specific subset of them. Think of it like syntax highlighting in your editor: no one is saying it'll make or break your project or that it's more important than code quality broadly speaking, it's just helpful.

I use Typescript for two main purposes:

  • Declare programmatically that I will never do something and rely on the computer to tell me when I do ("I will always pass an object that has a foo function that returns a string"). This is similar to linting and relies almost entirely on what you want to enforce. You can easily tell TS to leave you alone with any or you can be ultra specific { bla: (a: int, b (c: string) => boolean) => void }
  • Explore complex APIs more easily with auto-completion and type checking. The Apollo example is actually pretty good: Apollo tools have approximately 700 different options, with different types, etc. Not having to jump back to the documentation (or the source code itself) to know that it's addTypename and not includeTypename and that it's just a boolean and not a function is very helpful

I don't think you need to be at a large organization to get these benefits: you're always working with a gigantic codebase, either the browser or Node and probably at least one framework. You're also working with at least one of the most forgetful and error prone developer: yourself.

This article is very helpful about what exactly TS can help you with: css-tricks.com/types-or-tests-why-...