Commit 54349aa 1 parent 5669ab9 commit 54349aa Copy full SHA for 54349aa
File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -205,9 +205,12 @@ export class Entity extends EngineObject {
205
205
* @param type - The type of the component
206
206
* @returns The component which has been added
207
207
*/
208
- addComponent < T extends Component > ( type : new ( entity : Entity ) => T ) : T {
208
+ addComponent < T extends new ( entity : Entity , ...args : any [ ] ) => Component > (
209
+ type : T ,
210
+ ...args : ComponentArguments < T >
211
+ ) : InstanceType < T > {
209
212
ComponentsDependencies . _addCheck ( this , type ) ;
210
- const component = new type ( this ) ;
213
+ const component = new type ( this , ... args ) as InstanceType < T > ;
211
214
this . _components . push ( component ) ;
212
215
component . _setActive ( true , ActiveChangeFlag . All ) ;
213
216
return component ;
@@ -751,3 +754,10 @@ export class Entity extends EngineObject {
751
754
return this . _invModelMatrix ;
752
755
}
753
756
}
757
+
758
+ type ComponentArguments < T extends new ( entity : Entity , ...args : any [ ] ) => Component > = T extends new (
759
+ entity : Entity ,
760
+ ...args : infer P
761
+ ) => Component
762
+ ? P
763
+ : never ;
You can’t perform that action at this time.
0 commit comments