Basic Conditionals
Basic Conditionals
π¨βπΌ Let's create conditional types that check and transform based on type
conditions.
type IsNumber<T> = T extends number ? true : false
type UnwrapArray<T> = T extends Array<infer U> ? U : T
type A = IsNumber<42> // true
type B = UnwrapArray<Array<'x'>> // 'x'
π¨ Open
and:
- Create an
IsString<T>type that returnstrueorfalse - Create an
IsArray<T>type - Create a
Flatten<T>that unwraps arrays - Create
NonNullable<T>from scratch


