From 43af8cb3557d32644eb2f7498fe1b0ef4079af37 Mon Sep 17 00:00:00 2001 From: Muhammad Muhajir Date: Thu, 25 Apr 2024 09:44:38 +0700 Subject: [PATCH] fix: Make Entity Constructor's `components` option optional (#3027) 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): Entity', gave the following error. Argument of type '{ name: string; }' is not assignable to parameter of type 'EntityOptions'. Property 'components' is missing in type '{ name: string; }' but required in type 'EntityOptions'. Overload 2 of 2, '(components?: any[] | undefined, name?: string | undefined): Entity', 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 { name?: string; components: TComponents[]; } ``` Changes: - Make `components` options optional here. --- src/engine/EntityComponentSystem/Entity.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/EntityComponentSystem/Entity.ts b/src/engine/EntityComponentSystem/Entity.ts index 8c7fc1c91..4def52306 100644 --- a/src/engine/EntityComponentSystem/Entity.ts +++ b/src/engine/EntityComponentSystem/Entity.ts @@ -67,7 +67,7 @@ export const EntityEvents = { export interface EntityOptions { name?: string; - components: TComponents[]; + components?: TComponents[]; } /** @@ -122,7 +122,7 @@ export class Entity implements OnIniti nameToAdd = name; } else if (componentsOrOptions && typeof componentsOrOptions === 'object') { const { components, name } = componentsOrOptions; - componentsToAdd = components; + componentsToAdd = components ?? []; nameToAdd = name; } if (nameToAdd) {