Mapped conditional types (original) (raw)

#12114 added mapped types, including recursive mapped types. But as pointed out by @ahejlsberg

Note, however, that such types aren't particularly useful without some form of conditional type that makes it possible to limit the recursion to selected kinds of types.

type primitive = string | number | boolean | undefined | null; type DeepReadonly = T extends primitive ? T : DeepReadonlyObject; type DeepReadonlyObject = { readonly [P in keyof T]: DeepReadonly<T[P]>; };

I couldn't find an existing issue with a feature request.

Conditional mapping would greatly improve the ergonomics of libraries like Immutable.js.