何时重要的props是super(),为什么?
class MyComponent extends React.Component {
constructor(props) {
super(); // or super(props) ?
}
}
Run Code Online (Sandbox Code Playgroud) 我似乎无法解决此错误。
App.tsx(9,15)TS2339中的错误:类型“ {}”上不存在属性“ count”。
App.tsx
import React from "react";
import Test from "./Test";
const App = () => {
return (
<div>
<Test count={1} />
</div>
);
}
export default App;
Run Code Online (Sandbox Code Playgroud)
测试文件
import React from "react";
interface Props{
count: number
}
interface State{}
class Test extends React.Component<Props, State>{
render(){
return <div>{this.props.count}</div>;
}
}
export default Test;
Run Code Online (Sandbox Code Playgroud)
我的tsconfig如下,
{
"compilerOptions": {
"allowJs": true,
"jsx": "react",
"module": "es6",
"target": "es5",
"allowSyntheticDefaultImports": true
},
"include": ["src"]
}
Run Code Online (Sandbox Code Playgroud)
我也在使用webpack来构建应用程序。我正在加载打字稿ts-loader
package.json
"dependencies": {
"axios": …Run Code Online (Sandbox Code Playgroud)