Specifically, do you worry that Microsoft is going to eventually do the Microsoft thing and horribly fuck it up for everyone? I’ve really grown to appreciate the language itself, but I’m wary of it getting too ingrained at work only to have the rug pulled out from under us when it’s become hard to back out.

Edit: not really “pulling the rug”, but, you know, doing the Microsoft classic.

  • @[email protected]
    link
    fedilink
    -6
    edit-2
    9 months ago

    If I take my json and add a .yaml extension it works. If I take my c code and add a .cpp it works. If I take my js code and add a .ts … it doesn’t work

    TS branches off of the JS syntax (which is great! way better than a syntax rewrite), but TS is not a superset; it does not meet the practical or technical definition of a language superset.

    • @Kalabasa
      link
      English
      69 months ago

      What are the additional requirements? Afaik valid JS is valid TS.

      • @[email protected]
        link
        fedilink
        2
        edit-2
        9 months ago
        var foo = {};
        foo.bar = 42;
        

        Perfectly valid, and extremely commonly used, coding pattern in JavaScript - it’s essentially the normal way to do an associative array or hashmap in JavaScript. It’s also one of the commonly used ways to (poorly) simulate OOP in JavaScript.

        In TypeScript, it fails. You can’t treat an object as an arbitrary key/value pair. That’s a good thing… but still, it means TypeScript is not a superset of JavaScript.

        AFAIK that source code will be accepted by the TypeScript compiler if the file has a *.js extension, but that’s an ugly workaround and it also means you can’t copy/paste code between files. You have to rewrite the code.

        • @[email protected]
          link
          fedilink
          89 months ago

          In TypeScript, it fails. You can’t treat an object as an arbitrary key/value pair. That’s a good thing… but still, it means TypeScript is not a superset of JavaScript.

          No, it doesn’t fail. It compiles to perfectly valid JS that runs exactly as you’d expect. The type checking itself errors, because you’ve made an error - but the compilation isn’t prevented by this error.

          So yes, Typescript is a superset of JavaScript.

          • @[email protected]
            link
            fedilink
            1
            edit-2
            9 months ago

            That is an important difference. Still lots of people, myself included, classify “compiler printing an error (not a warning)” as failure, even if bizzarly the code still runs somehow.

            • @[email protected]
              link
              fedilink
              19 months ago

              That’s because you’re missing the distinction between compiler and type checker. The compiler doesn’t check types, it strips them. The type checker only checks types, it doesn’t compile. They are often used in conjunction, though increasingly the compilation is done by e.g. esbuild.

              But there is nothing “bizarre” about the code running, since literally, TS is a superset of JS.

          • @lolcabanon
            link
            19 months ago

            I know a cool library you can use to convert .ts files in Js! It’s called tsc!

            /s

      • @[email protected]
        link
        fedilink
        1
        edit-2
        9 months ago

        Type annotations. It can be as simple a adding any in front of parameters, but there are other edgecases too, and when you have a really big codebase it can be a pain to convert.

    • @mrkite
      link
      29 months ago

      Your own example fails because “class” is a valid variable name in c but not cpp.

      • @[email protected]
        link
        fedilink
        -1
        edit-2
        9 months ago

        I didn’t say C++ was a superset of C, I said “if I take my c code and add a cpp extension it works”. Believe me, I am painfully aware of the not-a-superset problem between C and C++. My point is Typescript doesn’t even meet the very loose “its practically a superset” relationship that C++ has with C.

        • @mrkite
          link
          English
          19 months ago

          if I take my c code and add a cpp extension it works

          and I pointed out that it doesn’t if your C code has a variable called “class”.

          • @[email protected]
            link
            fedilink
            19 months ago

            Don’t worry, none of my code uses that, designated initilizers, complex numbers, variable length arrays, typedef name overloading, unintilized constants, implicit void pointer casting, implicit function declarations, nested struct defintions, or any of the other exclusively-C features.