[-] Periodic@programming.dev 1 points 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.

Periodic

joined 1 year ago