If
#
introductionImplement a utils If
which accepts condition C
, a truthy return type T
, and a falsy return type F
. C
is expected to be either true
or false
while T
and F
can be any type.
For example:
ts
type A = If<true, 'a', 'b'>; // expected to be 'a'type B = If<false, 'a', 'b'>; // expected to be 'b'
View on GitHubts
type A = If<true, 'a', 'b'>; // expected to be 'a'type B = If<false, 'a', 'b'>; // expected to be 'b'
#
start pointtsTry
/* _____________ Your Code Here _____________ */typeIf <C ,T ,F > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <If <true, 'a', 'b'>, 'a'>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <If <false, 'a', 2>, 2>>];
take the challengetsTry
/* _____________ Your Code Here _____________ */typeIf <C ,T ,F > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <If <true, 'a', 'b'>, 'a'>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <If <false, 'a', 2>, 2>>];