Skip to content

Commit

Permalink
fix: Make Entity Constructor's components option optional (#3027)
Browse files Browse the repository at this point in the history
Had a conversation here https://discord.com/channels/1195771303215513671/1232877562804305920

```
From example in https://excaliburjs.com/docs/entities:
const entityWithName = new ex.Entity({name: 'Named Entity'});


No overload matches this call.
  Overload 1 of 2, '(options: EntityOptions<any>): Entity<any>', gave the following error.
    Argument of type '{ name: string; }' is not assignable to parameter of type 'EntityOptions<any>'.
      Property 'components' is missing in type '{ name: string; }' but required in type 'EntityOptions<any>'.
  Overload 2 of 2, '(components?: any[] | undefined, name?: string | undefined): Entity<any>', gave the following error.
    Object literal may only specify known properties, and 'name' does not exist in type 'any[]'.ts(2769)
Entity.d.ts(58, 5): 'components' is declared here.


It seems that components is not optional here

export interface EntityOptions<TComponents extends Component> {
    name?: string;
    components: TComponents[];
}

```

Changes:
- Make `components` options optional here.
  • Loading branch information
muhajirdev authored Apr 25, 2024
1 parent 67a4c2c commit 43af8cb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/engine/EntityComponentSystem/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const EntityEvents = {

export interface EntityOptions<TComponents extends Component> {
name?: string;
components: TComponents[];
components?: TComponents[];
}

/**
Expand Down Expand Up @@ -122,7 +122,7 @@ export class Entity<TKnownComponents extends Component = any> implements OnIniti
nameToAdd = name;
} else if (componentsOrOptions && typeof componentsOrOptions === 'object') {
const { components, name } = componentsOrOptions;
componentsToAdd = components;
componentsToAdd = components ?? [];
nameToAdd = name;
}
if (nameToAdd) {
Expand Down

0 comments on commit 43af8cb

Please sign in to comment.