00268-easy-if
Easy
utils

チャレンジのソース: type-challenges/00268-easy-if

条件値CCが truthy である場合の戻り値の型TCが falsy である場合の戻り値の型Fを受け取るIfを実装します。 条件値Ctruefalseのどちらかであることが期待されますが、TF は任意の型をとることができます。

例えば:

type A = If<true, 'a', 'b'>; // expected to be 'a'
type B = If<false, 'a', 'b'>; // expected to be 'b'

Loading...
テストケースの出典: type-challenges/00268-easy-if/test-cases.ts
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<If<true, 'a', 'b'>, 'a'>>,
  Expect<Equal<If<false, 'a', 2>, 2>>,
  Expect<Equal<If<boolean, 'a', 2>, 'a' | 2>>,
]

// @ts-expect-error
type error = If<null, 'a', 'b'>