I encountered an issue while using the following class and receiving a specific error within the for loop:
[ts] Argument of type 'Component' is not assignable to parameter of type 'ComponentType'. Type 'Component' provides no match for the signature 'new (): Component'
The structure of this class is as follows:
class Prefab {
public components: Component[] = [];
public static make(object: Prefab): GameObject {
let go = new GameObject;
for (let comp of object.components) {
// The error occurs here:
go.addComponent(comp);
}
return go;
}
}
Additionally, I have defined an interface for my component class:
interface ComponentType<T extends Component> {
new (): T;
}
Below is the definition for addComponent
:
addComponent<T extends Component>(type: ComponentType<T>): T;
How can I address this issue? Any suggestions would be appreciated.