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

    I’m in this post and I don’t like it.

    That being said I try to have specific types in my typescript but coming from working without typescript, there’s so much more words involved using typescript and for what I use it for I don’t really see the use case. Sure it helps you realize what part of the script needs what data types but it adds so much more complexity in the code that I’m not really sure it’s worth in the first place.

    • noli@programming.dev
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      1 year ago

      Typescript saves ridiculous amounts of time in bugfixes and is IMO a lot more readable than JS.

      I don’t know how many times TS has complained about some type mismatch in my code that made me scratch my head for 2 seconds to only then realize I was doing something stupid. With plain JS that would’ve been no issue, until I have some obscure bug 30 minutes later and have to figure out it’s source.

      Also, whatever piece of code you are working on, to do anything you have to have the types of your variables/functions in mind. If you have to keep track of all of them in your head, you will definitely mess it up at some point or have to look through a bunch of different methods/files to track down the source of some piece of data to be certain what’s contained in it.

      So yeah, TS might take slightly longer to type out, but it saves you a lot of dev time.

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

        I mean I guess that could be helpful, I’ve never really had that issue so I have yet to see the benefit of it. I just find it useless work that you’re typing out for something that the engine itself isn’t going to be able to see anyway, which means you’re going to have to have unit tests coded in regardless. And I wouldn’t say just a little more coding, typescript when implemented into my project doubled the amount of code provided, I’m trying to use it because I do understand it’s a standard, but I really don’t understand why it’s a universal standard, considering that everything it does is completely syntax sugar/coder side and it doesn’t actually interact with the underlying engine. I feel the same way about coffee script honestly.

        • jflorez@sh.itjust.works
          link
          fedilink
          arrow-up
          5
          ·
          1 year ago

          Just wait until you have to work as part of a team on a big project. The lack of types will murder the team’s productivity

        • jvisick@programming.dev
          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