I was talking to my manager the other day, discussing the languages we are using at $dayjob. He kind of offhandedly said that he thinks TypeScript is a temporary fad and soon everything will go back to using JavaScript. He doesn’t like that it’s made by Microsoft either.

I’m not a frontend developer so I don’t really know, but my general impression is that everything is moving more and more towards TypeScript, not away from it. But maybe I’m wrong?

Does anyone who actually works with TypeScript have any impression about this?

  • porgamrer@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    2 years ago

    5 years ago everything was moving to TypeScript. Now everything has moved. Developers are still catching up, but it will be one-way traffic from here.

    I’m guessing your manager thinks TypeScript is like CoffeeScript. It is not like CoffeeScript.

    Also, TypeScript is only the beginning. In the halls of the tech giants most devs view TypeScript as a sticking plaster until things can be moved to webassembly. It will be a long time until that makes any dent in JS, but it will also be one-way traffic when it does.

  • ShaunaTheDead@fedia.io
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    I don’t really get the appeal of strongly typed languages. Can’t you just use try/catch blocks, and/or use functional programming and return early if the data structure of whatever you’re working with isn’t what you expected?

    I guess it can help older code easier to maintain because the expected data structure is right there, but you could also just include it in a comment above the function.

    I personally find TS slows down initial production of a project and raises so many unnecessary errors.

    Is there some huge benefit that I’m missing? Because I don’t really get the appeal. I mean, I do on some level, but I don’t really understand why so many people are absolutely obsessed with TS.

    • abhibeckert@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      2 years ago

      Is there some huge benefit that I’m missing?

      For example I recently fixed a bug where a function would return an integer 99.9999% of the time, but the other 0.0001% returned a float. The actual value came from a HTTP request, so it started out as a string and the code was relying on dynamic typing to convert that string to a type that could be operated on with math.

      In testing, the code only ever encountered integer values. About two years later, I discovered customer credit cards were charged the wrong amount of money if it was a float value. There was no exception, there was nothing visible in the user interface, it just charged the card the wrong amount.

      Thankfully I’m experienced enough to have seen errors like this before - and I had code in place comparing the actual amount charged to the amount on the customer invoice… and that code did throw an exception. But still, it took two years for the first exception to be thrown, and then about a week for me to prioritise the issue, track down the line of code that was broken, and deploy a fix.

      In a strongly typed language, my IDE would have flagged the line of code in red as I was typing it, I would’ve been like “oh… right” and fixed it in two seconds.

      Yes — there are times when typing is a bit of a headache and requires extra busywork casting values and such. But that is more than made up for by time saved fixing mistakes as you write code instead of fixing mistakes after they happen in production.


      Having said that, I don’t use TypeScript, because I think it’s only recently become a mature enough to be a good choice… and WASM is so close to being in the same state which will allow me to use even better typed languages. Ones that were designed to be strongly typed from the ground up instead of added to an existing dynamically typed language.

      I don’t see much point in switching things now, I’ll wait for WASM and use Rust or Swift.

  • Cyclohexane@lemmy.ml
    link
    fedilink
    arrow-up
    0
    ·
    2 years ago

    The only valid argument against typescript is that it is too similar to vanilla JavaScript. It does not go far enough. We need type systems like Ocaml’s.

    I suppose you can also complain about needing a build step, but I find this silly. There are so many tools that make this easy or automatic.

      • Cyclohexane@lemmy.ml
        link
        fedilink
        arrow-up
        0
        ·
        2 years ago

        I won’t remember everything, but one very important things comes to mind:

        in Typescript, it is very difficult to assert on a type (let me know if you’re not familiar with what I mean by this and I can explain further). In OCaml, this is trivial using pattern matching.

        Why would you need that? The idea of a type system is it doesn’t let you apply a function on a structure without the structure being of the right type. But the lack of type assertion in TS makes people follow hacky workarounds, which defeat the purpose of type system.

        There are a couple of other things, like immutable types by default, automatic tail call optimization, functors enabling higher kinded types, etc.

        Also in ocaml, you don’t have to annotate any types on any variable or parameter, and you’ll still get full type protection.

        • laughterlaughter@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          2 years ago

          Oh, so what you’re describing is strong typing. I thought it was a unique feature of Ocaml. But in reality, any strong-typed language will have this as well.

          And yeah, Typescript merely “suggests” typing, and it will allow you to build the project even if you ignore the type errors. A build system refusing to, well, build, if there are typing errors usually takes care of this, but again, the dev team may as well not implement this.