Type alias If<T, A, B>

If<T, A, B>: T extends true ? A : T extends false ? B : A | B

A conditional type.

Example

type NotNull = If<true, string>; // string
type Null = If<false, string>; // null
type Optional = If<boolean, string>; // string | null

Type Parameters

  • T extends boolean

  • A

  • B = null