Get JavaScript intellisense with closures in VS 2019

81 views Asked by At

I organize my JavaScript code into "modules" to get namespace-like access such as foo.bar() and to hide internals from the global namespace.

var foo = foo || {};

// Intellisense would work for these declarations:
foo.bla = 0;
foo.blub = true;

// Self-invoking function for the module "foo".
(
    function () {

        // This closure represents the module "foo".
        
        // Intellisense is not working for any of these (from the outside):
        foo.bar = "bar";

        foo.baz = function () {
            const bazMessage = "baz";
            showMessage(bazMessage);
        };

        foo.bazz = function () {
            const bazzMessage = "bazz";
            showMessage(bazzMessage);
        };

        // This function is "private" and not seen globally.
        function showMessage(message) {
            alert(message);
        }
    }
);

My problem now is that Visual Studio does not provide intellisense for anything which is added to foo from within the module.

  • Does anyone know a possibility to get intellisense working for the described scenario?
  • Does anyone know an alternative way to accomplish namespace-like access and have intellisense?
0

There are 0 answers