Mapped conditional types · Issue #12424 · microsoft/TypeScript (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

@matt-hensley

Description

@matt-hensley

#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.