Add second type parameter to Partial<T>, Required<T>, and Readonly<T> to selectively modify properties #35703
Closed
5 tasks done
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
Search Terms
Partial Required Readonly
mapped types
Suggestion
Currently
Partial<T>
Required<T>
andReadonly<T>
apply their modifications wholesale to all properties ofT
, but oftentimes this is more than what you intend. We should consider adding a second type parameter to limit the properties affected by the modifier.Use Cases
Oftentimes it's necessary to make only a few or single property optional or required. This currently requires a lot of manual type intersection, as one needs to split the type apart, apply the mapped type on this subset, and reconstruct the full type. It would be much simpler if we moved this into these predefined mapped types to make them more powerful.
Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: