如何使用typescript访问React 15.6中的props和setState

时间:2017-08-19 12:23:26

标签: javascript reactjs typescript

将react应用程序更新为typescript 15.6之后,所有内容都会中断,因为它无法在React.Component上找到props和setState。

我一直在谷歌上搜索,但找不到任何打字的具体信息,可以转移到15.6。

mod <- train(Species ~ ., data = iris, method = "lda", preProc = list(ignore = "Sepal.Width"))

enter image description here

import * as React from "react";
import * as ReactDOM from "react-dom";

import { connect } from 'react-redux';

@connect(state => ({auth: state.auth}))
class App extends React.Component<{auth?: any}, any> {
      render() {
        if (this.props.auth.user == null) return <div><LoginModal /></div>;
        return <div>...stuff here...</div>
      }
}    

以下是该项目的依赖项。

ERROR in [at-loader] ./components/pages/tags/tag-item.tsx:74:78 
    TS2339: Property 'props' does not exist on type 'TagItem'.

ERROR in [at-loader] ./components/pages/tags/tag-item.tsx:76:14 
    TS2339: Property 'setState' does not exist on type 'TagItem'.

0 个答案:

没有答案