1. 5

    Thanks @mariusschulz, I find these blog posts helpful, as someone looking to move to Typescript after a few years using React + ES6. The way you go from JS to TS in steps makes it fairly easy for me to follow along.

    1. 1

      Glad you found my posts helpful! :)

    1. 2

      So what type is 80 + 1? This all appears to be subtyping which I always find difficult to grok.

      1. 3

        80 + 1 is not a literal, but a binary expression. A variable initialized with this value is of type number. Literal types will only be used for variables initialized with a literal:

        const x = 80;  // Type 80
        const y = 80 + 1;  // Type number
        1. 1

          But 80 + 1 has a type, and 80 has a type and 1 has a type, so does 80 have + defined for it? Does it have implicit conversion from type 80 to type number?

          1. 3

            The compiler automatically widens literal types if necessary. Adding two expressions of a numeric literal type or type number produces a value of type number.