开云访问入口

3个月前 (04-21)

题目

实现一个通用的类型Mutable,使类型T的全部属性可变(非只读)。 同题参见

例如:

interface Todo {
 readonly title: string;
 readonly description: string;
 readonly completed: boolean;
}
type MutableTodo = Mutable; // { title: string; description: string; completed: boolean; }

English

Implement the genericMutablewhich makes all properties inTmutable (not readonly). 对照阅读

For example

interface Todo {
 readonly title: string;
 readonly description: string;
 readonly completed: boolean;
}
type MutableTodo = Mutable; // { title: string; description: string; completed: boolean; }

答案

type Mutable = { -readonly [K in keyof T]: T[K] };

在线演示

作者:Laggage

出处:https://www.cnblogs.com/laggage/p/type-challenge-mutable.html 相关阅读

说明:转载请注明来源

你可能想看:

标签:string
分享给朋友:

继续阅读

若需了解「开云访问入口」的上下文,可结合站内栏目与相关篇目交叉阅读。

栏目用于追新,文内链接用于对照细节。两者配合可减少漏读与重复检索。

继续浏览时优先选择同栏目或相近主题,避免被站外镜像带偏。

站点导览

string · wiki · 科技 · 文化

页面按栏目组织。可先看导读,再进入相关篇目或返回列表。