News for hackers. Stuff that matters.
Re:Don't use functions as callbacks unless they're designed ... by tom_mellior on Saturday February 06, 2021 @10:27AM (#26047151)
Thanks for the explanation.

> If you upgrade your function from no second argument to a numeric second argument [...] It will not crash, because it still perfectly type-safe

It's type-safe using a definition of "type-safe" that is defined relative to the underlying JavaScript model of "corrupt the user's data rather than crash". It wouldn't be type-safe using most other languages' (including Python, for example) model of "functions have a type that includes the number of arguments, and applying them to the wrong number of arguments is meaningless and hence not considered type-safe".

It's fair for TypeScript to use this approach. But it is surprising to many of us, who view type systems as tools for ruling out some dumb functional bugs, not just crashes.

There are no comments on this comment yet.