Typescript有什么冷门但是很好用的特性?
前端精髓
共 1652字,需浏览 4分钟
·
2021-09-24 23:55
获取一个值的类型
let defaultState = {
foo: 7,
bar: 'hello'
};
type State = typeof defaultState;
let nextState: State = {
foo: 'seven',
bar: 'world'
};
// 不能将类型“{ foo: string; bar: string; }”分配给类型“{ foo: number; bar: string; }”。
// 属性“foo”的类型不兼容。
// 不能将类型“string”分配给类型“number”。
获取一个函数的返回值的类型
function getState() {
return {
foo: 7,
bar: 'hello'
};
}
type State = ReturnType<typeof getState>;
let nextState: State = {
foo: 'seven',
bar: 'world'
};
// 不能将类型“{ foo: string; bar: string; }”分配给类型“{ foo: number; bar: string; }”。
// 属性“foo”的类型不兼容。
// 不能将类型“string”分配给类型“number”。
将一个类型中的所有属性都变成可选属性
let defaultState = {
foo: 7,
bar: 'hello'
};
type PartialState = Partial<typeof defaultState>;
let partialState: PartialState = {
foo: 8
};
取出一个类型中的部分属性,生成另一个类型
let defaultState = {
foo: 7,
bar: 'hello'
};
type PickedState = Pick<typeof defaultState, 'foo'>;
let partialState: PickedState = {
foo: 8,
bar: 'world'
};
// 不能将类型“{ foo: number; bar: string; }”分配给类型“Pick<{ foo: number; bar: string; }, "foo">”。
// 对象文字可以只指定已知属性,并且“bar”不在类型“Pick<{ foo: number; bar: string; }, "foo">”中。
还有一些其他内置工具类型,可以在把鼠标放到 ReturnType 上,按 F12 查看
type Readonly<T> = {
readonly [P in keyof T]: T[P];
}
type Partial<T> = {
[P in keyof T]?: T[P];
}
type Nullable<T> = {
[P in keyof T]: T[P] | null;
}
type Proxy<T> = {
get(): T;
set(value: T): void;
}
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
}
type Record<K extends string, T> = {
[P in K]: T;
}
评论
有什么好用的协同办公软件?
例如:
1、x9系列办公协同管理系统
汇信外贸ERP系统支持与外贸办公协同管理系统建立数据无缝专属通道,进行信息交互传递, 业务零触点及时互动,实现公司两大系统双向管控,有效满足企业信息化运营管理目标。
http://www.ruanfujia.com/software/35685/
2、方天OA办公协同管理系统
方天OA办公协同管理系统主要针对大中型企业用户,适用于各类实施办公自动化建设的用户需求,包括政府、企业、工厂、教育、金融、证券、医院、电力、交通等各个行业领域。
http://www.ruanfujia.com/software/48718/
3、致远协同软件
致远协同管理软件定位于大中型企业、集团型企业、
软服之家
0
【Python】冷门,但好用的Python库!
来自萝卜大杂烩 Python 标准库有超过 200 个模块,程序员可以在他们的程序中导入和使用。虽然普通程序员对其中许多模块都有一些经验,但很可能有一些好用的模块他们仍然没有注意到。 我发现其中许多模块都包含了在各...
机器学习初学者
0
有好用的erp?
不可否认跨境电商ERP这一行鱼龙混杂,因为没有一个判断的标准,很多想要入行跨境电商的新手都陷入某些黑心之人的骗局,被割韭菜,交了钱,最后感觉自己什么都没得到,然后觉得卖ERP的都是骗子。
但是并不能一棍子打死一船人,每个行业存在都有其一定的道理。就跨境电商中智赢ERP来说,每年有很多新手,经过智赢正确的引导,跟随着智赢这条船,快速航行!
购买了我们的软件,我们会有系统的培训课程体系:
帮助新老卖家学习亚马逊开店、产品编辑技巧、运营技巧、行业选品、跨境物流操作细节等等,帮助卖家朋友避免再跨境电商的道路上踩坑,少走弯路。
比如初级课程会讲解亚马逊与智赢ERP的平台知识和运营技巧,内容围绕亚马逊卖家的日常工作,系统讲解亚马逊账
亚马逊小智赢
0