在一个TypeScript React项目中,我正在使用
react-dnd及其
DefinitelyTyped typings:
interface ExampleScreenProps { a,b,c } interface ExampleScreenState { x,y,z } class ExampleScreen extends React.Component<ExampleScreenProps,ExampleScreenState> { } export default DragDropContext(HTML5Backend)(ExampleScreen);@H_404_2@这被渲染在另一个组件中:
import ExampleScreen from "./ExampleScreen"; <ExampleScreen a="a" b="b" c="c" />@H_404_2@这在TS 1.8没有任何错误.当我升级到TS 2.0时,我得到以下编译错误:
Error:(90,10) TS2600: JSX element attributes type
‘(ExampleScreenProps & { children?: ReactNode; }) |
(ExampleScreenProps & { children…’ may not be a union type.这是type definition for
DragDropContext
:export function DragDropContext<P>( backend: Backend ): <P>(componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => ContextComponentClass<P>;@H_404_2@我不能把它放在一起抱怨的错误是什么?似乎它不喜欢ComponentClass< P> | StatelessComponent< P>,但是那些不是元素属性,元素属性简单地是< P>.我试图明确地通过< P> ;::
export default DragDropContext<ExampleProps>(HTML5Backend)(ExampleScreen);@H_404_2@export default DragDropContext(HTML5Backend)(ExampleScreen) as React.ComponentClass<ExampleProps>;@H_404_2@但我不喜欢使用断言,我不明白实际的问题,或者我做错了事情.这是可以解决的打字问题吗?