get_matching_components<T extends Component>(component_type_to_return: { new (doodad: Doodad): T }): T[]
{
return this.components.filter(component => component instanceof component_type_to_return)
}
In TypeScript, I created a method to retrieve components based on their type. Now, I want to convert this method into JSDoc format.
** THE UPDATED SOLUTION **
/**
* Retrieves components of a specified type if attached to the Doodad.
* @template {Component} T
* @param {{ new (doodad: Doodad): T }} type The type of component to retrieve
* @return {T[]} Array of all components of the specified type attached to the Doodad
*/
get_components(type)
{
return this.components.filter(component => component instanceof type)
}