类型体操

非空数组的类型,元素非空数组的类型

How to type a non-empty array in typescript?

typescript
1export type NonEmptyArray<T> = [T, ...T[]];

How to type a array which shouldn't contain nullable item?

typescript
1export type NonNullableElement<T> = T extends (infer U)[] ? NonNullable<U>[] : T;