Sometimes I think I don't understand TypeScript's type system and then I see something like this and I realize I know even less than I thought
These advanced type systems are essentially a form of pre-compile time scripting to assert certain guarantees about user defined types. It's the same mechanism that makes C++ templates turing complete.
[0] https://www.typescriptlang.org/docs/handbook/2/template-lite...
If feeling adventurous, read e.g. https://lpn.swi-prolog.org/lpnpage.php?pagetype=html&pageid=...
that's a great quote.
IIRC the type checker is literally a Prolog.
Conditional types are probably rarely used in practial code, but it opens the door for a lot of geekery.