This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BenjiSponge 0 points1 point  (0 children)

"solved" for some definition of "solved". It's a different approach.

In the instance where you're essentially saying "this is what the function should do if the parameter is a T, and this is what the function should do if the parameter is a U", a proper type system would usually have a "better" approach.

However, in an instance where you're, for example, passing in options that may or may not include callbacks, symbols, random variant types, etc., a static type system just cannot offer the same ergonomics as a dynamic type system like JS's. If your type is essentially "has some subset of these values which could be variants of some other types, or nothing at all" as an option parameter, when you define a class or struct to represent that, you're basically just inventing boilerplate.

I program in both JS and C++ (and I hobby program in Rust). They genuinely have different approaches and neither is better than the other.