在教程中我看到了这个
import React, { Component, PropTypes } from 'react'
class PureInput extends Component {
shouldComponentUpdate(nextProps) {
return this.props.field !== nextProps.field
}
render() {
const { field, ...rest } = this.props
return <input {...field} {...rest}/>
}
}
PureInput.propTypes = {
field: PropTypes.object.isRequired
}
export default PureInput
我在我的项目中尝试过像这样的打字稿
import * as React from 'react'
interface Props {
field: any
}
export class PureInput extends React.Component<Props, void> {
shouldComponentUpdate(nextProps) {
return this.props.field !== nextProps.field
}
render() {
const { field, ...rest } = this.props
return (<input {...field} {...rest} />)
}
}
它会在 ...rest 上发出错误警告,所以我该怎么办?,不确定我是否应该通过添加 [rest:string]:any 之类的代码来将 Props 接口添加到字典中,我已经尝试过了,它是不行