【发布时间】:2019-09-25 04:48:48
【问题描述】:
我正在尝试过滤一些道具,然后将其余道具传递给原生 html 元素,如下所示:
const Placeholder = (
display: boolean,
...rest: Array<React.LabelHTMLAttributes<HTMLLabelElement>>
) => <label {...rest} />
问题是这给了我这个错误:
Type '{ length: number; toString(): string; toLocaleString(): string; pop(): LabelHTMLAttributes<HTMLLabelElement> | undefined; push(...items: LabelHTMLAttributes<HTMLLabelElement>[]): number; ... 28 more ...; flat<U>(this: U[][][][][][][][], depth: 7): U[]; flat<U>(this: U[][][][][][][], depth: 6): U[]; flat<U>(this: U[]...' has no properties in common with type 'DetailedHTMLProps<LabelHTMLAttributes<HTMLLabelElement>, HTMLLabelElement>'.ts(2559)
如何为 Typescript / React 中的 label 等原生 html 元素定义 ...rest 参数的类型?
【问题讨论】:
-
试试
Array<React.LabelHTMLAttributes<T>>
标签: javascript reactjs typescript