[英]JSDoc: assign type to inline variable
我可以为从第三方库获取object
结果的变量分配类型吗?
const result = thirdPartyLib.doSomething();
现在我可能有一个ES6课程
class MyClass {
...
}
我想将result
注释为MyClass
类型。
可以使用JSDoc吗?
JSDoc @type {…}
标记可以应用于局部变量以声明其类型。
/** @type {MyClass} */
const result = thirdPartyLib.doSomething();
但是,您可以使用@external
标记将JSDoc类型添加到thirdPartyLib.doSomething()
,而不是在调用函数的所有位置添加此声明,从而可以正确推断局部变量类型。
/**
* @external thirdPartyLib
*/
/**
* @function external:thirdPartyLib.doSomething
* @returns {MyClass}
*/
const result = thirdPartyLib.doSomething();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.