I have the following higher order function for wrapping contructors:
/**
* Wrapper for calling constructor with given parameters
*
* @param {Class} Cls
* @returns {function} Wrapper on constructor which creates an instance of given Class
*/
function constructorWrapper(Cls) {
return (...args) => new Cls(...args);
}
So if I have a class MyClass, I can do the following:
exports.MyClass = MyClass;
exports.myClass = constructorWrapper(MyClass);
Now the class can be instantiated in the following 2 ways after importing:
const instance1 = new MyClass(param1, param2);
const instance2 = myClass(param1, param2);
In vscode, instance1 will have intellisense support but instance2 won't. How do I document the function/export so that the objects created using the wrapper are recognised as instances of the class?
![<code>function constructorWrapper<T>(Cls: new (...arg1: any[]) => T): (...arg0: any[]) => T</code>](https://www.lemona.fr/i.sstatic.net/XfL56.png)
![<code>myClass: (...arg0: any[]) => T</code>](https://www.lemona.fr/i.sstatic.net/vOwiN.png)
vscode, use Typescript instead :(