我怎样才能像 Typescript 中的 redux 表单的深度表单教程那样获得 {...rest}
How can I get {...rest} like this redux form's Deep form tutorial in Typescript
在 tutorial 我看到这个
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
我在我的项目中像这样尝试使用 Typescript
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 接口成为字典,我试过了还是不行
const { field, ...rest } = this.props
这还不支持。
更多
https://github.com/Microsoft/TypeScript/issues/2103
关注更新
在 tutorial 我看到这个
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
我在我的项目中像这样尝试使用 Typescript
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 接口成为字典,我试过了还是不行
const { field, ...rest } = this.props
这还不支持。
更多
https://github.com/Microsoft/TypeScript/issues/2103
关注更新