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
index.ts
and:
  1. Create an IsString<T> type that returns true or false
  2. Create an IsArray<T> type
  3. Create a Flatten<T> that unwraps arrays
  4. Create NonNullable<T> from scratch

Please set the playground first

Loading "Basic Conditionals"
Loading "Basic Conditionals"
Login to get access to the exclusive discord channel.
Loading Discord Posts