by kaleidawave on 10/30/24, 6:53 PM with 33 comments
by haileys on 11/1/24, 1:02 PM
No, not true!
As the author correctly states earlier in the post, unions are not an exclusive-or relation. Unions are often made between disjoint types, but not always.
This becomes important when T itself is nullable. Let's say T is `U | null`. `Option<Option<U>>` in Rust has one more inhabitant than `U | null | null` in TypeScript - `Some(None)`.
Union types can certainly be very useful, but they are tricky because they don't compose like sum types do. When writing `Option<T>` where T is a generic type, we can treat T as a totally opaque type - T could be anything and the code we write will still be correct. On the other hand, union types pierce this opacity. The meaning of `T | null` and the meaning of code you write with such a type does depend on what T is at runtime.
by nikeee on 11/1/24, 6:17 AM
Similar to this, I proposed inequality types for TS. They allow constraining a number range. For example, it is possible to have the type "a number that is larger than 1". You can combine them using intersection types, forming intervals like "a number between 0 and 1". Because TS has type narrowing via control flow, these types automatically come forward if you do an "if (a<5)". The variable will have the type "(<5)" inside the if block.
You can find the proposal here [1]. Personally I think the effort for adding these isn't worth it. But maybe someone likes it or takes it further.
by o11c on 10/31/24, 10:33 PM
`any`, however, is not `top`, it is `break_the_type_system`. The top type in TS is `unknown`.
by throwaway17_17 on 10/31/24, 10:25 PM
by James_K on 11/3/24, 11:12 AM
by skybrian on 10/31/24, 9:08 PM
I think they might have meant "entities" instead of "entries?"
The term "diagonal identity" seems to be non-standard as well?
by disqard on 11/1/24, 11:38 PM
I didn't feel satisfied with the explanation in TFA.
by Mathnerd314 on 11/1/24, 3:42 PM
Are these even types? I always mentally filed closures under "implementation detail of nested functions".
by ingen0s on 11/1/24, 8:27 AM