11
you are viewing a single comment's thread
view the rest of the comments
[-] 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.

this post was submitted on 27 Jun 2023
11 points (100.0% liked)

Programming

17025 readers
192 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS