【发布时间】:2017-11-28 14:51:06
【问题描述】:
我有这个.tsx 文件:
import React, { Component } from 'react';
export class SidebarItem extends Component {
constructor(props) {
super(props);
}
render() {
return (<li>{this.props.children}</li>);
}
}
但是,TypeScript 会抛出这个错误:
error TS2339: Property 'props' does not exist on type 'SidebarItem'.
【问题讨论】:
-
因为
this.props.children应该由 React 自动设置。这是您访问传递给组件的内容的方式。{path} -
另外
constructor (props) { super(props); this.props = props; }会抛出SidebarItem上不存在'props'的错误 -
您找到答案了吗?我在 tsc v2.3.4 上有同样的问题。你有用 TypeScript 编写 React 类组件的好链接吗?'
-
不。我放弃了尝试将 TypeScript 与 React 一起使用。
标签: reactjs typescript react-tsx