-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
#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> = T extends primitive ? T : DeepReadonlyObject<T>;
type DeepReadonlyObject<T> = {
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.
gentoo90, Artazor, canufeel, Bumbolio, ryanatkn and 141 moreremojansen, MeirionHughes, Magicolo, sparebytes, donaldpipowitch and 37 more
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript