reactjs – 具有react-dnd的TypeScript 2.0提供错误“JSX元素属
在一个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); 这被渲染在另一个组件中: import ExampleScreen from "./ExampleScreen"; <ExampleScreen a="a" b="b" c="c" /> 这在TS 1.8没有任何错误.当我升级到TS 2.0时,我得到以下编译错误:
这是type definition for export function DragDropContext<P>( backend: Backend ): <P>(componentClass: React.ComponentClass<P> | React.StatelessComponent<P>) => ContextComponentClass<P>; 我不能把它放在一起抱怨的错误是什么?似乎它不喜欢ComponentClass< P> | StatelessComponent< P>,但是那些不是元素属性,元素属性简单地是< P>.我试图明确地通过< P> ;:: export default DragDropContext<ExampleProps>(HTML5Backend)(ExampleScreen); 但同样的错误仍然存??在.我可以通过断言输出来解决它: export default DragDropContext(HTML5Backend)(ExampleScreen) as React.ComponentClass<ExampleProps>; 但我不喜欢使用断言,我不明白实际的问题,或者我做错了事情.这是可以解决的打字问题吗?
您可以使用以下方式安装新的打字:
npm i @types/react-dnd --save-dev 如果您已经安装其他打字,请使用: typings uninstall --save --global react-dnd 之后,它应该按预期工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |