'Construct signatures with JSDoc and TS-Pragma ts(2351)
I've a function that returns a constructor dynamically. When I try to instantiate the new object it warns me
This expression is not constructable.
Type 'myConstructor' has no construct signatures.ts(2351)
See example below:
// @ts-check
const BusinessDataConstructor = new myConstructor(Object.keys(businessData).join());
const business = new BusinessDataConstructor(); // ts.(2351) error
I'm using JS but defining all types with JSDoc and make VSCode check it with TS pragma. BusinessDataConstructor is inferring the myConstructor type correctly.
My function begins as follows:
/**
* @constructor
* @param {string} keys
*/
function myConstructor {
/** @constructor */
function constructor() { ... }
return constructor;
}
To add context it works like a charm on Javascript, no issues either in dev or in runtime. Already checked the JSDoc supported types reference and tried several options but none seem to work properly.
How can I declare the Construct signature using JSDoc?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
