• FooBarrington@lemmy.world
    link
    fedilink
    arrow-up
    12
    ·
    edit-2
    7 months ago

    Types help you prevent errors while writing the code instead of while running. That’s a massive benefit, as it literally makes a lot of errors impossible (as long as you don’t work around it) - otherwise you have to write a lot of tests to get the same guarantees, and you could always miss something by doing that.

    The other benefit is that it allows other developers to understand your code very, very quickly. Types describe what your data looks like - there is nothing more important in programming than that!

    When you install an NPM library and your editor gives you hints about parameter types, return types etc., that’s all Typescript types at work.

    • purpleprophy
      link
      fedilink
      English
      arrow-up
      4
      ·
      7 months ago

      After maintaining a huge JS codebase for years and finally upgrading it to TS, my life is so much easier. Refactoring is faster and less error-prone. I no longer have to manually document the parameter/return types for every function. I don’t have that gnawing “oh damn, what if I missed something” feeling whenever I make changes.

      Yes it’s a bit more work up front but it pays dividends on larger codebases.

    • andreax@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      7 months ago

      Your answer and mine are complementary, they definitely complete each other! Well done!