属性'Component'在'typeof React'类型上不存在

时间:2019-07-05 12:26:41

标签: javascript reactjs ecmascript-6

enter image description here使用create-react-app创建react-typescript项目后,我在VS Code中着重指出了

Property 'Component' does not exist on type 'typeof React'.

我的课看起来像这样:

import * as React from "react";

interface Props {
    number: number;
}

interface State {
    count: number;
};

export default class MyClass extends React.Component<Props, State> {
    constructor(public props: Props) {
        super(props);
        this.state = {
            count: 1
        }
    }
    render () {
        return (
          <div>
            {this.state.count}
          </div>
        );
      }
}

如果我将import语句更改为Import React,则将{Component}从“ react”导入; 我正在

Module '".../node_modules/@types/react/index"' has no exported member 'Component'

我已经安装了@ types / react @ types / react-dom。知道为什么VS代码找不到此模块吗?

0 个答案:

没有答案