> Wait so in Rust you can’t have an Option<Option<T>>?
You can, Rust has sum types rather than union types.
> That’s really bad!
I agree, but some people seem to like union types for some reason.
You can, because Rust doesn’t support first class Union, and uses ADTs. Something like Typescript allows you to write “(T | null) | null)” but that is not the same thing as a double-Option’d type.
Rust actually does have an untagged union type, but it generally requires some unsafe to use it, doesn't seem to get much use beyond c/ffi.
It was added specifically for c/ffi, so this is cool.
but the untagged union is still an aggregate at the type level right? Your data is a union at runtime, but at the type level it's a distinct thing, yeah? TS in particular is offering bespoke anonymous unions, which is a different sort of beast.
Of course, rust being nominally typed it is a distinct thing, while TS is structural. But that aspect should affect much more than just unions, (that said I personally know very little about typescript so talk my opinions here with a grain of salt).
In Rust you can, in Python an Optional[Optional[int]] is the same as an Optional[int].