diff --git a/jecs.d.ts b/jecs.d.ts index ff6398ee..8701f555 100644 --- a/jecs.d.ts +++ b/jecs.d.ts @@ -13,24 +13,32 @@ export type Tag = Entity; * A pair of entities * P is the type of the predicate, O is the type of the object, and V is the type of the value (defaults to P) */ -export type Pair

= number & { +export type Pair

= number & { __jecs_pair_pred: P; __jecs_pair_obj: O; - __jecs_pair_value: V; + __jecs_pair_value: P extends Entity + ? O extends Entity + ? V + : never + : P extends Entity ? V : never }; /** * Either an Entity or a Pair */ -export type Id = Entity | Pair; +export type Id = Entity | Pair, Entity>; + +type InferComponent = E extends Entity + ? T + : E extends Pair + ? E["__jecs_pair_value"] + : never; -type InferComponent = E extends Id ? T : never; type FlattenTuple = T extends [infer U] ? U : LuaTuple; type Nullable = { [K in keyof T]: T[K] | undefined }; type InferComponents = { [K in keyof A]: InferComponent; }; -type TupleForWorldGet = [Id] | [Id, Id] | [Id, Id, Id] | [Id, Id, Id, Id]; type Iter = IterableFunction>; @@ -136,7 +144,7 @@ export class World { * @param components Target Components * @returns Data associated with target components if it exists. */ - get(id: Entity, ...components: T): FlattenTuple>>; + get(id: Entity, ...components: T): FlattenTuple>>; /** * Returns whether the entity has the specified components. @@ -176,7 +184,7 @@ export class World { * @param obj The second entity (object) * @returns The composite key (pair) */ -export function pair(pred: Entity

, obj: Entity): Pair; +export function pair(pred: Entity

, obj: Entity): Pair, Entity>; /** * Checks if the entity is a composite key (pair) @@ -190,14 +198,14 @@ export function IS_PAIR(value: Id): value is Pair; * @param pair The pair to get the first entity from * @returns The first entity (predicate) of the pair */ -export function pair_first(pair: Pair): Entity

; +export function pair_first(pair: Pair): Entity

; /** * Gets the second entity (object) of a pair * @param pair The pair to get the second entity from * @returns The second entity (object) of the pair */ -export function pair_second(pair: Pair): Entity; +export function pair_second(pair: Pair): Entity; export const OnAdd: Entity<(e: Entity) => void>; export const OnRemove: Entity<(e: Entity) => void>;