Effect CommunityEC
Effect Community3y ago
11 replies
Kristian Notari

Understanding the Type Equality Check in TypeScript

Someone is able to ELI5 why the following type to check for type equality is like it is instead of simply checking if the two types both extend each other?
I know why you cannot use the two extends method, it doesn't work well with
never
for example, but why the actual type is written like that is something I can't understand. Why the generic thing as return type for those functions, for example?
type IsEqualTo<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
Was this page helpful?