type Mutable<T> = {
-readonly [k in keyof T]: T[k] extends symbol | string | boolean ? T[k] : Mutable<T[k]>
}
Solution by wendao-liu #35053
type Mutable<T> = {
-readonly [Key in keyof T]: T[Key]
}
Solution by devshinthant #34932
// your answers
type Mutable<T> = {
-readonly[K in keyof T]: T[K]
}
Solution by gobielJonathan #34482
type Mutable<T extends object> = {
-readonly [K in keyof T]: T[K]
}
Solution by ouzexi #34051
type Mutable
Solution by rookiewxy #33837
// your answers
type Mutable<T> = { -readonly [K in keyof T]: T[K] }
Solution by pea-sys #32904
type Mutable<T extends object> = { -readonly [K in keyof T]: T[K] }
Solution by dev-hobin #32500
type Mutable<T> = {
-readonly [K in keyof T]:T[K]
}
Solution by rkamely #32101
type Mutable<T extends readonly [] | Record<string, any>> = {
-readonly [P in keyof T]: T[P];
};
Solution by vipulpathak113 #31753
type Mutable<T> = {
-readonly [K in keyof T]:T[K]
}
Solution by MyeonghoonNam #31282
type Mutable<T extends object> = {
-readonly [K in keyof T]: T[K] extends object ? Mutable<T[K]> : T[K]
}
Solution by kai-phan #30975
type Mutable<T extends any[] | {[key:string]: any}> = {
-readonly[Key in keyof T]: T[Key]
}
// better
type Mutable<T extends object> = {
-readonly[Key in keyof T]: T[Key]
}
Solution by maximallain #30918
type Mutable<T extends object> = {
-readonly [K in keyof T]: T[K] extends Record<string, unknown> ? Mutable<T[K]> : T[K]
}
Solution by dreamluo-plus #30585
// 考虑到嵌套问题, 因此用MutableHandler做个中间转化
type MutableHandler<T> = T extends object ? Mutable<T> : T
type Mutable<T extends object> = {
- readonly [P in keyof T]: MutableSingle<T[P]>
}
interface Todo1 {
readonly title: string
readonly description: string
readonly completed: boolean
readonly meta: {
readonly author: string
}
}
interface Todo2 {
title: string
description: string
completed: boolean
meta: {
author: string
}
}
Expect<Equal<Mutable<Todo1>, Todo2>>
Solution by xiahouwei #30398
type Mutable<T extends object> = {
-readonly [k in keyof T]: T[k]
}
type MutTodo = Mutable<{readonly title: string; readonly description: string}>;
Solution by sundial-dreams #29486
type Mutable<T extends object> = { -readonly [Key in keyof T]: T[Key] }
Solution by hajeonghun #28818
type Mutable<T extends Record<keyof any, any>> = { -readonly [K in keyof T]: T[K]; };
Solution by DoubleWoodLin #28695
// your answers
type Mutable<T> = {
-readonly [K in keyof T]: T[K];
};
Solution by L1atte #28208
type Mutable<T extends object> = {
-readonly[K in keyof T]: T[K]
}
Solution by ashishbinu #27920
type Mutable<T extends Record<PropertyKey, any>> = {
-readonly [K in keyof T]: T[K]
}
Solution by jjswifty #27628
// your answers
type Mutable<T extends any[] | object> = {
-readonly [K in keyof T]: T[K]
}
Solution by daiki-skm #27578
type Mutable<T extends object> = {
-readonly [P in keyof T]: T[P]
}
Solution by 8471919 #27485
type Mutable<T extends Record<PropertyKey, any>> = {
-readonly [K in keyof T]: T[K]
}
Solution by RainbowIsPerfect #27426
type Mutable<T> = { -readonly [K in keyof T]: T[K] }
Solution by smileboyi #26950
type Mutable<T> = {
-readonly [K in keyof T]: T[K];
};
Solution by ryuji-1to #26881
type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
Solution by rldnd #26858
type Mutable<T extends Record<string, any>> = {
-readonly [K in keyof T]
: T[K] extends Record<string, any>
? Mutable<T[K]>
: T[K]
}
Solution by avatar0813 #26802
type Mutable<T> = {
-readonly [P in keyof T]: T[P]
}
Solution by isntkyu #26772
type Mutable<T extends Record<PropertyKey, any> > = {
-readonly [Key in keyof T]: T[Key]
}
Solution by HaoxueAllen #26528
// your answers
type Mutable<T extends object> = {
-readonly [P in keyof T]: T[P];
};
Solution by rayjayjin #26117