Consider this scenario: I have created a type that can only hold one specific value:
export type IfEqual<T, U> =
(<G>() => G extends T ? 1 : 2) extends
(<G>() => G extends U ? 1 : 2) ? true : false;
By using the following declaration, I am able to assign values a
, which will always be true
, and b
, which will always be "foo"
.
declare const a: IfEqual<'a', 'a'>; // automatically set as true
declare const b: IfEqual<'a', 'a'> extends true ? "foo" : "bar"; // resolved as "foo"
Given that the type has only one possible value, I wonder if there's a way to directly convert that type into its corresponding value.