If
Implement the util type If<C, T, F> which accepts condition C, a truthy value T, and a falsy value F. C is expected to be either true or false while T and F can be any type.
For example:
tstypeCannot find name 'If'.2304Cannot find name 'If'.A =<true, 'a', 'b'> // expected to be 'a' If typeCannot find name 'If'.2304Cannot find name 'If'.B =<false, 'a', 'b'> // expected to be 'b' If
tstypeCannot find name 'If'.2304Cannot find name 'If'.A =<true, 'a', 'b'> // expected to be 'a' If typeCannot find name 'If'.2304Cannot find name 'If'.B =<false, 'a', 'b'> // expected to be 'b' If
Solution ✅
tstypeIf <C ,T ,F > =C extends true ?T :C extends false ?F : nevertypeA =If <true, 'a', 'b'> // expected to be 'a'typeB =If <false, 'a', 'b'> // expected to be 'b'typeC =If <{}, 'a', 'b'> // expected to be never
tstypeIf <C ,T ,F > =C extends true ?T :C extends false ?F : nevertypeA =If <true, 'a', 'b'> // expected to be 'a'typeB =If <false, 'a', 'b'> // expected to be 'b'typeC =If <{}, 'a', 'b'> // expected to be never