• cgtjsiwy
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    1 year ago

    Although I’ve used a number of languages including Python, Javascript, and Go to build software, the bulk of my experience is working in Java.

    Notably, Python’s type annotations are extremely similar to Typescript. I guess the author hadn’t used Python’s type annotations very much (which is understandable considering they’re often missing from libraries and the implementations are buggier than Typescript).

  • Periodic
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I’ve seen a similar journey occur with a few devs on my teams. The types may initially look like types in a language like Java, but they are very different in some important ways. Ultimately, just remember that the system is there to help you prevent bugs, not necessarily to fully describe the program. Unlike in some other languages the type information doesn’t really affect the compiled code. That’s why overloading doesn’t work. It’s just a tool to help you as a dev.

    For example, records are extensible. Every record type is basically an interface. That means {} is not the type of the empty object, it’s actually the type for any object!

    I think it helps to remember that under the hood everything in JavaScript is just objects and functions (and a few primitives). Even classes are just syntactic sugar on top!

    But you can get into some really cool-stuff with the conditional types. For example, it’s possible to write a generic type that accepts any array of promises as a parameter and then results in a single promise containing an array of the promise values, even if that array is a tuple.