Deep Readonly
#
introductionImplement a generic DeepReadonly<T>
which make every parameter of an object - and its sub-objects recursively - readonly.
You can assume that we are only dealing with Objects in this challenge. Arrays, Functions, Classes and so on are no need to take into consideration. However, you can still challenge your self by covering different cases as many as possbile.
For example
ts
type X = {x: {a: 1b: 'hi'}y: 'hey'}type Expected = {readonly x: {readonly a: 1readonly b: 'hi'}readonly y: 'hey'}const todo: DeepReadonly<X> // should be same as `Expected`
View on GitHubts
type X = {x: {a: 1b: 'hi'}y: 'hey'}type Expected = {readonly x: {readonly a: 1readonly b: 'hi'}readonly y: 'hey'}const todo: DeepReadonly<X> // should be same as `Expected`
#
start pointtsTry
/* _____________ Your Code Here _____________ */ÂtypeDeepReadonly <T > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <DeepReadonly <X >,Expected >>,]ÂtypeX = {a : () => 22b : stringc : {d : booleane : {g : {h : {i : truej : 'string'}k : 'hello'}}}}ÂtypeExpected = {readonlya : () => 22readonlyb : stringreadonlyc : {readonlyd : booleanreadonlye : {readonlyg : {readonlyh : {readonlyi : truereadonlyj : 'string'}readonlyk : 'hello'}}}}
take the challengetsTry
/* _____________ Your Code Here _____________ */ÂtypeDeepReadonly <T > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <DeepReadonly <X >,Expected >>,]ÂtypeX = {a : () => 22b : stringc : {d : booleane : {g : {h : {i : truej : 'string'}k : 'hello'}}}}ÂtypeExpected = {readonlya : () => 22readonlyb : stringreadonlyc : {readonlyd : booleanreadonlye : {readonlyg : {readonlyh : {readonlyi : truereadonlyj : 'string'}readonlyk : 'hello'}}}}