// Conditional types: https://github.com/Microsoft/TypeScript/pull/21316 // Remove null and undefined from T type NonNullableValue = T extends null ? never : T extends undefined ? never : T type NonNullable = { [K in keyof T]: NonNullableValue } type Nullable = { [K in keyof T]: T[K] } declare const ensureNonNull: (value: Nullable) => NonNullable declare const val: { a: number | null, b: string | undefined } const nonNullVal: { a: number, b: string } = ensureNonNull(val) // `infer`: https://github.com/Microsoft/TypeScript/pull/21496 type Obj = { key: K, value: V } type ReturnSplit = AC extends (...args: any[]) => Obj ? { [k in K]: V } : never declare const func: (someParam: number) => Obj<'SomeString', Array> type T0 = ReturnSplit const t0: T0 = { SomeString: [1] } type Animals = { ant: { a: string }, bat: { b: number }, cat: { c: boolean }, } type UnionOf = T[keyof T] type T1 = UnionOf // We can assign any of the values to a variable of type T1 const t1a: T1 = { a: '' } const t1b: T1 = { b: 2 } const t1c: T1 = { c: false } // Thanks to these new features now we can create an intersection type export type IntersectionOf = ({ [K in keyof T]: (x: T[K]) => void }) extends Record void> ? V : never type T2 = IntersectionOf const t2: T2 = { a: '', b: 3, c: true }