• Presi300@lemmy.world
    link
    fedilink
    English
    arrow-up
    5
    arrow-down
    8
    ·
    10 months ago

    As someone who is relatively new to webdev stuff, I gotta ask… what is the point of typescript? Like, is it faster than JS, does it have more functions or smth? To me it just looks like JS with extra steps and a really, REALLY cursed way to declare variables.

    • ebc@lemmy.ca
      link
      fedilink
      arrow-up
      15
      ·
      10 months ago

      As a beginner you don’t see the benefits as it is indeed JS with extra steps. It’s not worth it for small projects and prototypes, but once you start having larger projects where you need to refactor something, you’ll see the benefits.

      Also, auto-complete.

    • Tau@sopuli.xyz
      link
      fedilink
      arrow-up
      7
      ·
      10 months ago

      It helps for when you have a variable that’s for numbers and you use it as a string or something else, it shouts an error. In other words, it protects you from yourself

    • traches@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      4
      ·
      10 months ago

      Typescript gives you better suggestions, red squiggles where you would get errors or bugs if you try to run it, more information about whatever it is you’re using that’s defined somewhere else, and some other neat stuff like project-wide renaming that works every time.

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

      No, it is slower than JS but it can be compiled to JS. The point of typescript is bringing static (or generally talking, predictable) types to variables, so that treating erroneously a number as a string should be more difficult. In a large codebase, it’s easy to make mistakes and debugging is not instantaneous but it needs time. Typescript helps here. You write more code but it helps you out later

      • mea_rah@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        10 months ago

        I don’t have much experience with TS, but in other strongly typed language it goes even further than string vs number.

        For example you can have two numbers Distance and TimeInSeconds and even though they are both numbers, the type system can make sure that you won’t do distance+time.

        It can also let you do distance/time and return Speed type.

        It will prevent many logical errors even though everything is technically a number.