简体   繁体   English

指定在另一个文件中声明的全局变量的类型

[英]Specify type of globals declared in another file

How can I tell my IDE (PHPStorm) that certain global variables aren't "undeclared", but simply declared elsewhere; 我如何告诉我的IDE(PHPStorm)某些全局变量不是“未声明”的,而是在其他地方声明的; and have a specific type? 并有特定的类型?

An example from Magento ( opcheckout.js ): 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

A first part of answer - how to mark them as externally declared: 答案的第一部分-如何将其标记为外部声明:

Put a normal var declaration to the beginning of "importing" file. 将普通的var声明放在“导入”文件的开头。

This (a bit surprisingly) doesn't replace 'global' with 'module local' because JS doesn't have module local variables. 这(有点令人惊讶)没有用“模块本地”替换“全局”,因为JS没有模块本地变量。

For the second part - I'm using PyCharm and it seems like handling such cases quite fine, at least in 2.0 EAP. 对于第二部分-我正在使用PyCharm,至少在2.0 EAP中,似乎可以很好地处理此类情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM