Skip to content

tsx 组件中使用 this.props.xxx 时,tslint 会报错 #2088

@nigelvon

Description

@nigelvon

问题描述
使用Typescript的tsx开发,组件中使用任何除了children的属性时,tslint都会报错。

export default class Test extends Component {
  static defaultProps = {
    xxx: '',
  }
  render() {
    return <View>{this.props.xxx}</View>
  }
}

现在解决办法是

const { xxx } = this.props as any
return <View>{xxx}</View>

期望行为
期望tslint能不报错

报错信息
[ts] 类型“Readonly<{}> & Readonly<{ children?: any; }>”上不存在属性“xxx”。

系统信息
Taro CLI 1.2.9 environment info:
System:
OS: macOS 10.14.2
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.13.0 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
npmGlobalPackages:
typescript: 3.0.1

补充信息
看了一下源码,props里只有children属性

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions