11
top 2 comments
sorted by: hot top controversial new old
[-] cgtjsiwy@programming.dev 3 points 1 year ago* (last edited 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@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.

load more comments
view more: next ›
this post was submitted on 27 Jun 2023
11 points (100.0% liked)

Programming

16991 readers
215 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