DEV Community

Discussion on: TypeScript vs JavaScript

Collapse
 
willsmart profile image
willsmart • Edited

My 2c is that Javascript has a wide array of traps for inexperienced devs to step into, and many/most of these are no longer issues when the dev is working in Typescript.
For example,

  • what does this refer to at any point in time?
  • type coercion rules causing problems
  • expecting an undefined from a system function that returns null

Even just the fact that object keys are reported as strings is enough to trip a coder up...

const barChart = {1:1, 2:4, 3:3},
      indexForTop = Object.entries(barChart).reduce(([k1,v1], [k2,v2])=> v1>v2 ? [k1,v1] : [k2,v2])[0] 
Enter fullscreen mode Exit fullscreen mode

Typescript will let you know that indexForTop is a string.

If coding is like putting a new roof on a house, having better static analysis tools, like type safety or good linting, is like setting up a better scaffold around the house before you start.
It is a pita in many ways but I'd think (apples to apples) that novice roofers need that safety more than the experienced ones.

Collapse
 
jheysonsaav profile image
Jheyson Saavedra • Edited

Correct