sketch-retired icon indicating copy to clipboard operation
sketch-retired copied to clipboard

[tpl-react-redux] hoc component props intelligence suggestion

Open zzswang opened this issue 7 years ago • 4 comments

Requirement

class A extends React.Component {
   static propTypes = { ... }
}

const B = props => <A { ...props } />;
B.propTypes = { ... A.propTypes }

when we use B outside, no intelligence suggestion for B.

zzswang avatar Oct 29 '18 14:10 zzswang

感觉只能试试TypeScript或者flow了:https://flow.org/en/docs/react/hoc/

0neSe7en avatar Oct 29 '18 14:10 0neSe7en

flow 和 ts 带来好处的同时 又增加了一些负担 哎

再看看,这个 issue 会先留在这里,作为提醒

zzswang avatar Oct 29 '18 15:10 zzswang

flow 和 ts 带来好处的同时 又增加了一些负担 哎

这个是肯定的。这些相当于带来了约束。而有的时候约束是方便,有时候就是负担了... 还有一种办法应该也可以,就是给这个component写一个 d.ts 。这可能是侵入最少的了。 类似这种,https://github.com/clauderic/react-sortable-hoc/blob/master/types/index.d.ts

0neSe7en avatar Oct 29 '18 15:10 0neSe7en

嗯嗯 👍

如果是发部成对外的组件,应该必须这么写。好像 antd 就是这么做的。

我和邵辰还发现一个 插件,也许有改造的空间

vscode 里的 React PropTypes Intellisense

它现在只能提示 A 的,也许可以改造

zzswang avatar Oct 29 '18 16:10 zzswang