3

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
demonkoryu
  • 1,247
  • 10
  • 27

1 Answers1

2

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.

Guard
  • 6,816
  • 4
  • 38
  • 58
  • The second part followed from the first part. Which worked. Thanks! – demonkoryu Sep 23 '11 at 10:37
  • great to hear it. btw, jetbean's IDEs seem to be by far the best in autocompletion, they even analyze dict keys used in the called function and all the script-included files (and looks like even their inter-calls) which is mind-blowing to me. – Guard Sep 23 '11 at 20:12
  • Yeah, I'm amazed by Jetbrains' stuff. I didn't think that I would ever come across an IDE that supports PHP refactoring; and understands stuff like SASS. – demonkoryu Sep 24 '11 at 12:50