Mutable
约 136 字小于 1 分钟
2026-02-11
题目
实现一个通用的类型 Mutable<T>,使类型 T 的全部属性可变(非只读)。
例如:
interface Todo {
readonly title: string
readonly description: string
readonly completed: boolean
}
type MutableTodo = Mutable<Todo> // { title: string; description: string; completed: boolean; }解题思路
待补充
答案
type Mutable<T> = any验证
import type { Equal, Expect } from '@type-challenges/utils'
interface Todo1 {
title: string
description: string
completed: boolean
meta: {
author: string
}
}
type List = [1, 2, 3]
type cases = [
Expect<Equal<Mutable<Readonly<Todo1>>, Todo1>>,
Expect<Equal<Mutable<Readonly<List>>, List>>,
]
type errors = [
// @ts-expect-error
Mutable<'string'>,
// @ts-expect-error
Mutable<0>,
]参考
无
