Get Readonly Keys
#
introductionImplement a generic GetReadonlyKeys<T>
that returns a union of the readonly keys of an Object.
For example
ts
interface Todo {readonly title: string;readonly description: string;completed: boolean;}type Keys = GetReadonlyKeys<Todo>; // expected to be "title" | "description"
View on GitHubts
interface Todo {readonly title: string;readonly description: string;completed: boolean;}type Keys = GetReadonlyKeys<Todo>; // expected to be "title" | "description"
#
start pointtsTry
/* _____________ Your Code Here _____________ */typeGetReadonlyKeys <T > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <'title',GetReadonlyKeys <Todo1 >>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <'title' | 'description',GetReadonlyKeys <Todo2 >>>];ÂinterfaceTodo1 {readonlytitle : string;description : string;completed : boolean;}ÂinterfaceTodo2 {readonlytitle : string;readonlydescription : string;completed ?: boolean;}
take the challengetsTry
/* _____________ Your Code Here _____________ */typeGetReadonlyKeys <T > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <'title',GetReadonlyKeys <Todo1 >>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <'title' | 'description',GetReadonlyKeys <Todo2 >>>];ÂinterfaceTodo1 {readonlytitle : string;description : string;completed : boolean;}ÂinterfaceTodo2 {readonlytitle : string;readonlydescription : string;completed ?: boolean;}