Skip to content

Instantly share code, notes, and snippets.

View miyaokamarina's full-sized avatar
😶

Marina Miyaoka miyaokamarina

😶
View GitHub Profile
type DeepReadonly<T> =
T extends [infer A] ? DeepReadonlyObject<[A]> :
T extends [infer A, infer B] ? DeepReadonlyObject<[A, B]> :
T extends [infer A, infer B, infer C] ? DeepReadonlyObject<[A, B, C]> :
T extends [infer A, infer B, infer C, infer D] ? DeepReadonlyObject<[A, B, C, D]> :
T extends [infer A, infer B, infer C, infer D, infer E] ? DeepReadonlyObject<[A, B, C, D, E]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F] ? DeepReadonlyObject<[A, B, C, D, E, F]> :
T extends [infer A, infer B, infer C, infer D, infer E, infer F, infer G] ? DeepReadonlyObject<[A, B, C, D, E, F, G]> :
T extends (infer A)[] ? DeepReadonlyArray<A> :
T extends Function ? T : // can change to never to forbid functions