javascripttypescriptvisual-studio-codejsdocrhino

JSDoc to handle Rhino's importPackage


In Rhino, one can do

importPackage(Packages.foo.bar.xyzzy);

This imports in the current namespace all the members of the Java foo.bar.xyzzy class.

I've already set up Typescript declaration files for that class so I can use

var x = Packages.foo.bar.xyzzy.memberA;
var y = Packages.foo.bar.xyzzy.memberB;

and get completion, type checking etc in VSCode (and the typescript that it uses)

With that importPackage, I can use

var z = memberA;

and it works (at run time) but VSCode complains because it has no idea that importPackage means that the members are imported.

Can I add some JSDoc that will cause VSCode to know that? It's a sort of

 import * from Packages.foo.bar.xyzzy

I guess

EDIT:

class xyzzy extends Packages.foo.bar.xyzzy {}

gets me close, but two problems: Rhino doesn't support class (so I need it to be in a JSDoc comment instead) and it means I can do xyzzy.methodY() now, but not just methodY()

My typescript-fu isn't that strong so I'm not really sure how to go about this


Solution

  • I'm afraid, there is no way to do what you want via typescript + jsdoc. importPackage works like a with statement. It modifies current execution context. TypeScript itself doesn't support types for with. Also, JavaScript doesn't have such conception as import * from "foo" (The correct one import * as foo from "foo").

    enter image description here