• jvisick
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    TypeScript is essentially the “measure twice, cut once” approach to JavaScript.

    Yeah, anything can be anything in JS and the type declarations don’t make it into the compiled JS, but allowing anything to be anything starts to become fairly dangerous when the size of your projects starts to grow and especially when you’re working with a team.

    Rather than writing functions and just hoping they always get called with a parameter that has the properties you expect to use, TypeScript helps you make sure that you always are calling that function with the right object in the arguments. You don’t need to debug some runtime error up and down 8 frames in the call stack because this week you named a property “maxValue” but last week you used “maxVal” or you forgot to parseInt some string because you thought it would be coerced - you just need to make sure your types match and eliminate that type of debugging altogether.

    All in all, TS really just enforces a bit of sanity to the foot gun that is vanilla JS.

    • Pika@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Yeah I fully agree typescript does help in terms of knowing what type of types you should be supplying to functions, and for the most part I do use it for non-library purpose/anything that doesn’t rely on a third party, I just feel like typescript isn’t worth it when you have data that’s returned at run time that’s controlled by a third party service. You end up coding more in class definition files then you would just using normal tests