Typescript 在类型上映射时,如何使键不是只读的?

Typescript 在类型上映射时,如何使键不是只读的?,typescript,mapped-types,Typescript,Mapped Types,问题很简单,正如标题所示:当从readonly类型映射时,如何使键可写(而不是只读) f、 e type Foo=Readonly type Bar=/*如何复制Foo类型,但使其可写*/ 使用-readonly在映射时删除readonly,例如 export type Foo = Readonly<{ foo: number bar: number }>; export type Writeable<T> = { -readonly [P in keyof

问题很简单,正如标题所示:当从
readonly
类型映射时,如何使键可写(而不是只读)

f、 e

type Foo=Readonly
type Bar=/*如何复制Foo类型,但使其可写*/

使用
-readonly
在映射时删除readonly,例如

export type Foo = Readonly<{
  foo: number
  bar: number
}>;

export type Writeable<T> = {
  -readonly [P in keyof T]: T[P];
};

export type Bar = Writeable<Foo>;
let x:Bar = {
  foo: 123,
  bar: 456
}
x.bar = 123; // OK 
导出类型Foo=Readonly;
导出类型可写={
-只读[P in keyof T]:T[P];
};
导出类型栏=可写;
设x:Bar={
foo:123,
酒吧:456
}
x、 bar=123;//好啊

使用
-readonly
在映射时删除readonly,例如

export type Foo = Readonly<{
  foo: number
  bar: number
}>;

export type Writeable<T> = {
  -readonly [P in keyof T]: T[P];
};

export type Bar = Writeable<Foo>;
let x:Bar = {
  foo: 123,
  bar: 456
}
x.bar = 123; // OK 
导出类型Foo=Readonly;
导出类型可写={
-只读[P in keyof T]:T[P];
};
导出类型栏=可写;
设x:Bar={
foo:123,
酒吧:456
}
x、 bar=123;//好啊

很好,谢谢!也许
writeable
可以成为标准库的一部分?很好,谢谢!也许
可写的
可以成为标准库的一部分?