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

RecursiveReadonly and RecursivePartial #18591

Closed
NN--- opened this issue Sep 20, 2017 · 1 comment
Closed

RecursiveReadonly and RecursivePartial #18591

NN--- opened this issue Sep 20, 2017 · 1 comment

Comments

@NN---
Copy link

NN--- commented Sep 20, 2017

Suggestion to add types to lib.d.ts:

type RecursiveReadonly<T> = {
	readonly [P in keyof T]: RecursiveReadonly<T[P]>;
};

type RecursivePartial<T> = {
    [P in keyof T]?: RecursivePartial<T[P]>;
};

Difference from Readonly and Partial

type ComplexType = { a: { b: { c: { d: number; } } } };

const x:Readonly<ComplexType> = {
    a: { b: { c: { d: 1 } } }
};
const xx: RecursiveReadonly<ComplexType> = {
    a: { b: { c: { d: 1 } } }
};
x.a.b.c.d = 3;
//xx.a.b.c.d = 3; // Error

const y:Partial<ComplexType> = {};
const yy: RecursivePartial<ComplexType> = {};

//y.a = {};// Error
yy.a = {}; // OK

Playground

@kitsonk
Copy link
Contributor

kitsonk commented Sep 20, 2017

Duplicate of #13923

@NN--- NN--- closed this as completed Sep 20, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants