Strata - v1.4.10
    Preparing search index...

    Function hasComponents

    • Checks if an entity has all specified components.

      Type-safe component validation. Checks both presence and non-undefined value for each component key.

      Type Parameters

      Parameters

      • entity: T

        The entity to check.

      • ...components: (keyof T)[]

        Component keys to check for.

      Returns boolean

      True if entity has all components with non-undefined values.

      const entity = { position: { x: 0, y: 0, z: 0 }, health: 100 };

      if (hasComponents(entity, 'position', 'health')) {
      // TypeScript knows entity has position and health
      console.log(`Health: ${entity.health}`);
      }