是否有一种可接受的方式(最好与 IDE 兼容)来记录 ES6 中的形状嵌套成员?
例如
class Foo extends React.Components {
constructor(props) {
super(props);
this.props.bar; // Webstorm for example will think 'bar' is not a member of props
}
}
我们可以做些什么来帮助 IDE 理解类成员的预期结构吗?像这样的东西:
/** @member {string} props.bar **/
在类声明或构造函数的顶部
最佳答案
@property
有点效果,但感觉不稳定。
/**
* @property {object} props
* @property {number} props.bar
*/
class Foo extends React.Components {
constructor(props) {
super(props);
}
}
丑陋如 hell ,但工作起来却像发条一样:
class Foo extends React.Components {
constructor(props) {
super(props);
/** @type {{foo: {bar: {}}}} */
this.props = this.props;
}
}
关于javascript - 如何使用嵌套结构记录 ES6 类成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37162637/