• hperrin@lemmy.ca
      link
      fedilink
      English
      arrow-up
      1
      ·
      4 hours ago

      Considering TypeScript is a superset of JavaScript, you certainly can. But, that generally means you’re using TypeScript poorly.

        • hperrin@lemmy.ca
          link
          fedilink
          English
          arrow-up
          1
          ·
          3 hours ago

          Yeah, I’ve seen a lot of those videos where they do things like {} + [], but why would anyone care what JS does in that case? Unless you’re a shit-ass programmer, you’re never going to be running code like that.

          The idea behind that kind of type conversion was that JS was originally designed to be extremely lenient. If it ever crashed, the web page would freeze, so it lets you do things other languages just crash from, like divide by zero.

          • namingthingsiseasy@programming.dev
            link
            fedilink
            arrow-up
            2
            ·
            2 hours ago

            Yeah, I’ve seen a lot of those videos where they do things like {} + [], but why would anyone care what JS does in that case? Unless you’re a shit-ass programmer, you’re never going to be running code like that.

            By this same logic, memory safety issues in C/C++ aren’t a problem either, right? Just don’t corrupt memory or dereference null pointers. Only “a shit-ass programmer” would write code that does something like that.

            Real code has complexity. Variables are written to and read from all sorts of places and if you have to audit several functions deep to make sure that every variable won’t be set to some special value like that, then that’s a liability of the language that you will always have to work around carefully.

          • FishFace@piefed.social
            link
            fedilink
            English
            arrow-up
            3
            ·
            3 hours ago

            A language’s deficiencies are rarely obvious when everyone is writing it perfectly.

            But a coherent type system gives the programmer confidence - for free. Do you know what [1] + [2] is in JavaScript? Do you know what type it is? JavaScript teaches you that it has operator overloading for built-in types but then it behaves in such a dumb way you can’t use it.

            That’s explained by a desire to be extremely lenient, but it’s not justified by it. Programming langauges are generally not made by idiots, so every bad decision has an explanation.