【问题标题】:Use of subtract operator and in keyword in the implementation of typescript Required<T>在 typescript Required<T> 的实现中使用减法运算符和 in 关键字
【发布时间】:2020-04-12 06:43:32
【问题描述】:

我发现这就是 Required&lt;T&gt; 在 typescript 中的实现方式:

type Required<T> = {
    [P in keyof T]-?: T[P];
};

只是想知道,除了遍历类型中的属性之外,in 关键字还有其他典型用例吗?

其次,- 的这种用法对我来说似乎是一种魔法。这个-还有其他用例吗?

【问题讨论】:

标签: typescript


【解决方案1】:

- 删除了使属性成为可选的? 修饰符——使该属性不再是可选的。 in 运算符has uses in JavaScript but iterating through a type's properties is its only TypeScript use

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-10
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多