我在类型定义中prop-types遇到了这一行:
export type ValidationMap<T> = { [K in keyof T]-?: Validator<T[K]> };
Run Code Online (Sandbox Code Playgroud)
没有-它将是一个非常标准的部分映射类型,但我找不到它所谈论的文档中的任何地方-?.
谁能解释一下是什么-?意思?
bas*_*rat 22
+或-允许控制映射的类型修饰符(?或readonly).-?意味着必须全部存在,也就是说它删除了选择性(?),例如:
type T = {
a: string
b?: string
}
// Note b is optional
const sameAsT: { [K in keyof T]: string } = {
a: 'asdf', // a is required
}
// Note a became optional
const canBeNotPresent: { [K in keyof T]?: string } = {
}
// Note b became required
const mustBePreset: { [K in keyof T]-?: string } = {
a: 'asdf',
b: 'asdf' // b became required
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2392 次 |
| 最近记录: |