重现的最小例子:
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):错误TS2346:提供的参数与呼叫目标的任何签名都不匹配。
这是一个错误吗?我错过了一些tsc
命令行标志/选项吗?
编辑:
安装类型:
tsc版本是2.3.4
答案 0 :(得分:2)
尝试使用es6导入代替React,并确保将delcare用于道具。
e.g。
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>;
}
}