【发布时间】:2020-04-25 16:19:38
【问题描述】:
我正在学习打字稿,我正在学习本教程:https://blog.alexdevero.com/react-and-typescript-pt3/。
当他谈到界面时,他会以以下方式使用它:
// Create interface for class component props
interface PropsInterface {
heading: string;
}
// Create interface for class component state
interface StateInterface {
firstName: string;
lastName: string;
}
class MyApp extends React.Component<PropsInterface, StateInterface> {
// This state annotation is optional
// it is for better type inference
state: StateInterface = {
firstName: 'Andrew',
lastName: 'Coboll'
}
render() {
return (
<div>
{this.props.heading} {this.state.firstName} {this.state.lastName}
</div>
)
}
}
包含接口的尖括号是什么意思?
最好的问候
【问题讨论】:
标签: reactjs typescript class interface