TypeScript & React/JSX:提供道具以反应组件的超类时出现 tsc 编译器错误
TypeScript & React/JSX: tsc compiler error when supplying props to react component's superclass
要重现的最小示例:
const React = require("react");
class ExampleForm extends React.Component {
constructor(props) {
super(props);
}
render() {
return <p>{ this.props.msg }</p>;
}
};
编译命令:
tsc --jsx react react_components/example.tsx
错误:
react_components/example.tsx(5,9): error TS2346: Supplied parameters do not match any signature of call target.
这是一个错误吗?我是否缺少一些 tsc
命令行 flag/option?
编辑:
安装类型:
- "@types/react": "^15.0.25"
- "@types/node": "^7.0.23"
tsc 版本为 2.3.4
尝试为 React 使用 es6 导入,并确保为 props 声明接口。
例如
import * as React from 'react';
interface IProps {
msg: string;
}
export class ExampleForm extends React.Component<IProps, {}> {
constructor(props: IProps) {
super(props);
}
render() {
return <p>{this.props.msg}</p>;
}
}
要重现的最小示例:
const React = require("react");
class ExampleForm extends React.Component {
constructor(props) {
super(props);
}
render() {
return <p>{ this.props.msg }</p>;
}
};
编译命令:
tsc --jsx react react_components/example.tsx
错误:
react_components/example.tsx(5,9): error TS2346: Supplied parameters do not match any signature of call target.
这是一个错误吗?我是否缺少一些 tsc
命令行 flag/option?
编辑:
安装类型:
- "@types/react": "^15.0.25"
- "@types/node": "^7.0.23"
tsc 版本为 2.3.4
尝试为 React 使用 es6 导入,并确保为 props 声明接口。
例如
import * as React from 'react';
interface IProps {
msg: string;
}
export class ExampleForm extends React.Component<IProps, {}> {
constructor(props: IProps) {
super(props);
}
render() {
return <p>{this.props.msg}</p>;
}
}