赞
踩
type React<K entends keyof any, T> = {
[P in K]: T;
}
用法
type Foo = Record<‘a’, string> // 相当于 type Foo = { a: string }
type Bar = {
b: string
}
type Baz = Record< keyof Foo | keyof Bar, number > // typ Baz = { a: number, b: number }
注解:可以用于创建 也可以用于合并然后重新赋值。 感觉没什么用
type Partial = {
[P in keyof T]?: T[P];
};
用法
type IFoo = {
a?: string,
b: string
}
const foo: Partial = { a: ‘1’ } // 变为可选
const bar: Required<Partial> = { // 变为全部必选
a: ‘1’,
b: ‘2’
}
type Readonly = {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。