It depends very much on whether it’s present pervasively in the language or not. TypeScript’s flow-sensitive type-narrowing, limited though it is in certain ways, is pervasive in the language and is incredibly useful. I miss it whenever writing Rust or Swift.
However, when applied to optional types in TS or in C♯, the semantics are quite different than they are with Swift optionals, because in TS’s case they’re representing an untagged union, T | null
; and in C♯’s case they’re dealing with a type marked as nullable but not an enumerated type as in the case of Swift/Rust/other ML-influenced languages.
The net is that it would have to implicitly unwrap the type, and it wouldn’t be a very general feature (unless it could be designed as a kind of sugar for which some protocol conformance would supply the type flow, perhaps—at which point we’re well out of my pay grade ).