DEV Community

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

Collapse
 
bradymholt profile image
Brady Holt • Edited

Kudos for the constructive criticism here. I really like having these types of discussions about technical things because I feel like our craft has issues with mob-mentality and we all just jump on the bandwagon of adoption without fully considering a tool in the context of our environment.

Full disclosure: I'm a fan of TypeScript. IMHO TypeScript is one tool in a war chest and not a silver bullet. I think those that expect that TS will "fix all your JS problems at build time" will be disappointed. But, it certainly does catch some things at build time along with providing some fantastic dev tooling.

To some of your points:

  1. "you can just use Babel" re: older browsers and ESNext features but if TypeScript can do those things and others, it seems like you're killing 2 birds with one stone, right?
  2. "Typed JS is long and difficult to read" - sometimes, yes. TypeScript has gotten pretty good with implicit typing so it can infer the types and they don't have to explicitly defined. For example, if your function returns a string you could declare a variable with the result and it will be typed as a string (const foo = myStringFunction())...no foo:string needed. Anyway, verbosity in code doesn't really bother me.

The dev tooling is one of the most compelling things in my opinion. There is some effort involved in getting everything setup and avoiding :any for everything but I think it's worth that effort, especially for a larger project.

Recently I was building an app that used an API client library published on npm that had TypeScript definitions defined in it. I imported the module and started calling API endpoint method wrappers and the types clearly defined (and enforced) the shape of the request body and explained (and enforced) how I worked with the response data. If I was missing a require field, it was obvious. If I referred to a field that did not exist or was misspelled, it was obvious. This all felt very productive and helpful. It was all made possible because of TypeScript.