在打字稿2.3.1中传播tsx中的反应道具

Ste*_*Wan 5 typescript

我有一些代码用于在typescript 2.2中编译好,但在2.3.1中失败:

class Component<T extends object> extends React.Component<T, {}> {
  render() { return <div { ...this.props }></div>; }
}
Run Code Online (Sandbox Code Playgroud)

我现在得到:

ERROR in ./file.tsx
(34,17): error TS2698: Spread types may only be created from object types.
Run Code Online (Sandbox Code Playgroud)

我怀疑这是由PR(在编写时未合并)修复的,但与此同时,有没有办法解决这个问题?

Tom*_*rez 0

我遇到了类似的错误,typescript@2.3.2
这是一个快速解决方法:<div { ...this.props as any }></div>