【发布时间】:2018-10-25 17:06:29
【问题描述】:
我正在尝试将我的 react/flux 项目从 typescript 2.2 更新到 2.8。
我使用 container.create 实用函数定义了以下商店:
import * as React from 'react';
import { Container } from 'flux/utils';
export let MyContainer = Container.create(class extends React.Component<props, state> {
static getStores() {
return [/* list of stores here*/]
}
static calculateState(prevState: state, props: props): state {
return {hello: true}
}
render() {
return <div>something</div>
}
}, { withProps: true });
如果我导出这个组件并尝试使用它,我会收到以下错误:
TS2605: JSX element type 'Component<props, ComponentState>' is not a constructor function for JSX elements.
这在我使用 typescript 2.2 时运行良好,但更新后我在任何地方都出现错误,我尝试像这样使用容器组件。
我使用的是 @types/react 类型版本 15.0.28。 Here are the definitions for Flux Containers.
【问题讨论】:
-
从这里尝试
rm -rf node_modules && rm yarn.lock && yarngithub.com/DefinitelyTyped/DefinitelyTyped/issues/21242 -
我没有使用纱线,这不是我的 node_modules 目录中安装的东西的问题
-
@theycallmemorty,如果你愿意,你可以用 npm 本身试试,最好在升级时先试一试
-
你能确保你有
"allowSyntheticDefaultImports": truetsconfig.json吗? typescriptlang.org/docs/handbook/compiler-options.html -
@theycallmemorty,对我的评论或现有答案有任何反馈吗?
标签: reactjs typescript flux