【发布时间】:2019-12-19 03:45:31
【问题描述】:
我是打字稿的新手,这个问题让我很困惑。 这是我的代码。
import { IProps, IState } from './types';
class Profile extends Component<RouteComponentProps & IProps, IState>{
state: IState = {
form: {
first_name: this.props.user.first_name,
last_name : this.props.user.last_name,
email : this.props.user.email,
phone : this.props.user.phone || ''
},
isLoading: false
};
validator = new SimpleReactValidator({autoForceUpdate: true});
render () {
const { user } = this.props;
const { form, isLoading } = this.state;
return (<div></div>)
}
}
export default Profile;
这些是我的类型:
export interface IState {
form: {
[key: string]: any;
};
isLoading: boolean;
}
export interface IProps {
children?: Element;
user : any;
}
这是我的 index.ts:
import Profile from './pages/profile/Profile';
const mapStateToProps = (state: IAppState) => {
return {
user: state.Auth.user
};
};
export default connect(mapStateToProps)(Profile);
我的代码编辑器将(配置文件)突出显示为错误。
我的终端抛出以下错误:
“typeof Profile”类型的参数不能分配给>“ComponentType”类型的参数。 类型“typeof Profile”不可分配给类型“ComponentClassany>”。
我想知道是否可以在此处进行代码更改以修复此 Typescript“错误”。
【问题讨论】:
-
如果您尝试将 index.ts 代码移动到 Profile ts 文件中,然后从那里默认 Profile,会发生什么情况,它会显示同样的错误吗?
-
我试过了,但还是出现了同样的错误。
标签: reactjs typescript react-redux typescript-typings