【发布时间】:2020-01-06 11:34:11
【问题描述】:
我需要为接收 prop name(应该是 Fields 的值)和任何其他 props 的 React 组件定义类型。
所以我尝试了类似的方法
type Fields = 'address' | 'recipientName' | 'recipientPhone';
type Props = {
name: Fields
[key in string]: any // error here
};
但它不起作用。我收到此错误:
类型文字中的计算属性名称必须引用其类型为文字类型或“唯一符号”类型的表达式。
如何创建这种类型?
【问题讨论】:
-
把
[key in string]改成[key: string]?
标签: typescript typescript-typings