I am trying to get my IDE (WebStorm) to understand that the getComponent method (or any other method) returns a new object created from the class type passed as a parameter.
Here is the code for the function with JSDoc:
/**
* Retrieves a component of the specified type from the list of components.
*
* @template T
* @param {T} component - The type of component to retrieve.
* @return {T} - he component of the specified type, or undefined if not found.
*/
getComponent(component) {
return this.components.find(c => c instanceof component);
}
And then I use this method like this:
const btn = gameObject.getComponent(Button);
The problem is that WebStorm doesn't realize that an object of class T is returned, not the passed type of T. Is it even possible to write a JSDoc to specify that a method ALWAYS returns an OBJECT of class T, not just the passed T?