taro icon indicating copy to clipboard operation
taro copied to clipboard

props 定义可选参数,defaultProps有默认值,提示 [ts] 对象可能为“未定义”。

Open ccode-code opened this issue 8 years ago • 1 comments

如下图: image image 组件定义了泛型current字段是可选参数,定义了静态defaultProps 的current为0。 使用的是否提示对象可能为“未定义”,可选参数存在undefined类型。

期望行为:当父级没有传递current的值,current应该是number类型的0。 bug级别:非优先。

系统信息

  • 操作系统: macos
  • Taro 版本 1.0.0-beta.24
  • Node.js 版本 v10.5.1
  • typescript 版本 3.0.3

ccode-code avatar Sep 06 '18 06:09 ccode-code

这点其实原生 React 也没有做到,只能做到写了 defaultProps 使用组件不用传入 props。这样一来 interface 就不用写可选参数了,一样可以做到相同的事情。

ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html

yuche avatar Jan 09 '19 09:01 yuche