Is there a way to document the function, so vscode-intellisense knows that getObject("player") returns a Player type and getObject("bullet") returns a Bullet type?
/**
* @param {string} type
* @return {????}
*/
function getObject(type) {
switch (type) {
case 'player': return new Player();
case 'bullet': return new Bullet();
}
}
An example of this functionality would be document.createElement(...).
document.createElement("canvas") => intellisense knows it's a HTMLCanvas type.
You cannot do this with jsdocs.
document.createElement uses typescript function overload definitions for its behavior. You could also use a *.d.ts this way:
declare function getObject(x: 'player'): Player;
declare function getObject(x: 'bullet'): Bullet;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With