268. If
小于 1 分钟
268. If
<题目描述>
::: playground#ts 268. If
@file index.ts
// ============= Test Cases =============
import type { Equal, Expect } from '@type-challenges/utils'
type cases = [
Expect<Equal<If<true, 'a', 'b'>, 'a'>>,
Expect<Equal<If<false, 'a', 2>, 2>>,
]
// @ts-expect-error
type error = If<null, 'a', 'b'>
// ============= Your Code Here =============
type If<C, T, F> = any
:::
点击查看答案
type If<C extends true | false, T, F> = C extends true ? T : F