Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new type: DeepMutable<T> #114

Open
dosentmatter opened this issue Oct 21, 2019 · 1 comment
Open

Add new type: DeepMutable<T> #114

dosentmatter opened this issue Oct 21, 2019 · 1 comment

Comments

@dosentmatter
Copy link
Contributor

dosentmatter commented Oct 21, 2019

Is your feature request related to a real problem or use-case?

Related to #27 and #111.
We have DeepPartial<T>, DeepRequired<T>, and DeepReadonly<T>. We should also add DeepMutable<T>.

Similar to #112, maybe we should have a DeepOptional<T> that would be an alias of DeepPartial<T>.

Describe a solution including usage in code example

export type DeepMutable<T> = T extends ((...args: any[]) => any) | Primitive | null | undefined
  ? T
  : T extends _DeepMutableArray<any>
  ? _DeepMutableArray<T[number]>
: T extends _DeepMutableObject<infer U>
  ? _DeepMutableObject<U>
  : never;
/** @private */
// tslint:disable-next-line:class-name
export interface _DeepMutableArray<T> extends Array<DeepMutable<T>> {}
/** @private */
export type _DeepMutableObject<T> = {
  -readonly [P in keyof T]: DeepMutable<T[P]>
};

Who does this impact? Who is this for?

TypeScript users.

@piotrwitek
Copy link
Owner

Hey, thanks for the suggestion, it would be great to have this type.
Contributions are welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants