I'm using TypeScript to detect typing problems in plain JavaScript. This is possible via a limited set of JSDoc tags.
However, there's one strange issue with it. When a member is created in the constructor, its type isn't set.
In the screenshot below, VS Code complains correctly about assigning a number to a string inside the update method, and directly on an instance. But it doesn't notice the incorrect assignment in the constructor.
This only seems to happen in the constructor, as creating a member in the update method does mark the typing issue.
Is there a way to force these type checks also in the constructor?
Code:
// @ts-check
function MyClass() {
/** @type {string} */
this.str = 0;
};
MyClass.prototype.update = function() {
this.str = 0
/** @type {number} */
this.num = ""
}
let inst = new MyClass()
inst.str = 0
inst.num = ""

@member {string}?@memberisn't supported for TypeScript. I did try it, but then it doesn't complain about anything. And the reason I used an image is because otherwise it won't show the squiggles. But I'll add the code too.