While it's definitely not quite the same idea, Typescript supports run-time type predicates that inform the type system.
https://www.typescriptlang.org/docs/handbook/2/narrowing.htm...
function isFish(pet: Fish | Bird): pet is Fish {
return (pet as Fish).swim !== undefined;
}
Which I've found extremely useful