指定在另一个文件中声明的全局变量的类型
我如何告诉我的 IDE (PHPStorm) 某些全局变量不是“未声明”的,而是简单地在其他地方声明的;并有特定的类型?
来自 Magento 的示例 (opcheckout.js
):
if (response.duplicateBillingInfo) {
shipping.setSameAsBilling(true); // "shipping undeclared" warning
}
// in fact, shipping is a global variable with constructor "Shipping".
我想做的是这样的:
/** @var Shipping window.shipping */
shipping.setS // with autocompletion:
setSameAsBilling
How can I tell my IDE (PHPStorm) that certain global variables aren't "undeclared", but simply declared elsewhere; and have a specific type?
An example from Magento (opcheckout.js
):
if (response.duplicateBillingInfo) {
shipping.setSameAsBilling(true); // "shipping undeclared" warning
}
// in fact, shipping is a global variable with constructor "Shipping".
What I'd like to do is something like this:
/** @var Shipping window.shipping */
shipping.setS // with autocompletion:
setSameAsBilling
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案的第一部分 - 如何将它们标记为外部声明:
将普通的
var
声明放在“导入”文件的开头。这(有点令人惊讶)并没有用“模块局部”替换“全局”,因为 JS 没有模块局部变量。
对于第二部分 - 我正在使用 PyCharm,它似乎可以很好地处理此类情况,至少在 2.0 EAP 中是这样。
A first part of answer - how to mark them as externally declared:
Put a normal
var
declaration to the beginning of "importing" file.This (a bit surprisingly) doesn't replace 'global' with 'module local' because JS doesn't have module local variables.
For the second part - I'm using PyCharm and it seems like handling such cases quite fine, at least in 2.0 EAP.