TypeScript

Take a function like below… type Combinable = string | number function add(a: Combinable, b: Combinable): Combinable { if (typeof a === 'string' || typeof b === 'string') { return a.toString() + b.toString() } return a + b } If we were to use this function like this: const x = add('black cat', 'white dog') x.split(' ') // TS compiler will complain here TypeScript cannot determine what the return type of add is at this point. ...

## Nullish Coalescing

// say you have some var hangin' around called name let x: string = name ?? '(no name)' ?? is the nullish coalescing operator. It differs from || in that if you had (in the above example) let x: string = name || '(no name)' name equal to an empty string (which is falsey) x would then be assigned the value (no name). The nullish coalescing operator will only use the right-hand assignment for “nullish” values (null or undefined). ...

## Recursive Type Aliases

In TS@4 a type can reference itself, e.g. type JSONValue = | string | number | boolean | null | JSONValue[] | { [k: string]: JSONValue } Previously, this would not be possible without some messy hacks.