I'm using VSCode 1.41.1 (November 2019 release). I have some JavaScript classes in a folder like so:
a.js
class A {
constructor() {
this.m = 2;
}
}
export default A;
b.js
class B {
constructor() {
this.n = 4;
}
}
export default B;
I am trying to gather them into a single library so that I can do something like Lib.A to refer to the A class.
My current method is this:
lib.js
import A from './a';
import B from './b';
class Lib {};
Lib.A = A;
Lib.B = B;
export default Lib;
I then would like to use the Lib class in an external app. I have this file:
app.js
import Lib from './lib';
/**
* @param {Lib.A} a
* @param {Lib.B} b
*/
function foo(a, b) {
}
However, when I mouse over the params a
or b
, the tool tips say (parameter) a: typeof A
and (parameter) b: typeof B
, respectively, and not (parameter) a: A
and (parameter) b: B
like I would expect. Additionally, the auto-completion when I do a.
shows the A class properties, and not an instance of A (with the m
member), just like the tool tips imply.
I have a more complex project whose import/export code hasn't changed, and this behavior didn't exist in it a few months ago. It seems like a VSCode update perhaps?
Or maybe I'm not combining the A and B classes or exporting the Lib class correctly? Or maybe the JSDoc that I'm using has changed how param typing is declared?
Thank you for any help you can give.
Edit: I've also tried for the Lib export:
const Lib = {
A,
B
};
But this makes the VSCode Intellisense for the foo function parameters just show any
as their type.
Also, I see that just doing:
const a = new Lib.A();
The intellisense does correctly make the variable a
as a type A
. So perhaps I'm just doing the JSDoc @param
declaration wrong?