TypeScript属性’props’不存在

前端之家收集整理的这篇文章主要介绍了TypeScript属性’props’不存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个.tsx文件
import React,{ Component } from 'react';

export class SidebarItem extends Component {
    constructor (props) {
        super(props);
    }

    render () {
        return (<li>{this.props.children}</li>);
    }
}

但是,TypeScript会抛出此错误
错误TS2339:类型’SidebarItem’上不存在属性’props’.

解决方案是安装React Types定义
yarn add -DE @types/react

来自typescript docstypes repo的更多细节

在旁注中我不得不重新启动vscode以使linting正确启动.

原文链接:https://www.f2er.com/react/300724.html

猜你在找的React相关文章