Skip to content

Commit 7261eea

Browse files
committed
test: fix type errors in test files with precise type assertions
Replace generic `as any` assertions with more precise types: - Use `createComponentId()` for ComponentId type creation - Use `Number()` conversion for numeric value assertions - Use `EntityId<any>` for array element deallocate operations - Use proper return type assertions for method calls - Remove unused variable declarations to clean up unused imports
1 parent 95d0e27 commit 7261eea

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

src/__tests__/command-buffer-limits.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe("CommandBuffer iteration limit", () => {
5555
it("should execute all commands within iteration limit", () => {
5656
const world = new World();
5757
const Value = component<{ num: number }>();
58-
const Tag = component<void>();
5958

6059
const entity = world.new();
6160

src/__tests__/component-registry.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, expect, it } from "bun:test";
22
import { ComponentIdAllocator } from "../core/entity-manager";
3-
import { COMPONENT_ID_MAX } from "../core/entity-types";
3+
import { COMPONENT_ID_MAX, createComponentId } from "../core/entity-types";
44

55
describe("ComponentIdAllocator", () => {
66
it("should allocate component IDs sequentially", () => {
@@ -10,9 +10,9 @@ describe("ComponentIdAllocator", () => {
1010
const id2 = allocator.allocate();
1111
const id3 = allocator.allocate();
1212

13-
expect(id1).toBe(1);
14-
expect(id2).toBe(2);
15-
expect(id3).toBe(3);
13+
expect(id1).toBe(createComponentId(1));
14+
expect(id2).toBe(createComponentId(2));
15+
expect(id3).toBe(createComponentId(3));
1616
});
1717

1818
it("should throw when exceeding COMPONENT_ID_MAX", () => {
@@ -57,7 +57,7 @@ describe("ComponentIdAllocator", () => {
5757

5858
for (let i = 1; i <= COMPONENT_ID_MAX; i++) {
5959
const id = allocator.allocate();
60-
expect(id).toBe(i);
60+
expect(id).toBe(createComponentId(i));
6161
}
6262

6363
// Should be exhausted now

src/__tests__/entity-id-manager.test.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from "bun:test";
22
import { EntityIdManager } from "../core/entity-manager";
3+
import type { EntityId } from "../testing";
34

45
describe("EntityIdManager", () => {
56
it("should allocate entity IDs sequentially", () => {
@@ -10,9 +11,9 @@ describe("EntityIdManager", () => {
1011
const id3 = manager.allocate();
1112

1213
// Entity IDs start at 1024
13-
expect(id1).toBe(1024);
14-
expect(id2).toBe(1025);
15-
expect(id3).toBe(1026);
14+
expect(Number(id1 as unknown as number)).toBe(1024);
15+
expect(Number(id2 as unknown as number)).toBe(1025);
16+
expect(Number(id3 as unknown as number)).toBe(1026);
1617
});
1718

1819
it("should reuse freed entity IDs (LIFO)", () => {
@@ -57,9 +58,9 @@ describe("EntityIdManager", () => {
5758
expect(manager.getFreelistSize()).toBe(0);
5859

5960
// Free every third ID
60-
const toReuse: number[] = [];
61+
const toReuse = [];
6162
for (let i = 0; i < allocated.length; i += 3) {
62-
manager.deallocate(allocated[i]!);
63+
manager.deallocate(allocated[i]! as EntityId<any>);
6364
toReuse.push(allocated[i]!);
6465
}
6566

@@ -104,17 +105,19 @@ describe("EntityIdManager", () => {
104105

105106
it("should throw when deallocating invalid entity ID", () => {
106107
const manager = new EntityIdManager();
107-
const id = manager.allocate();
108+
manager.allocate();
108109

109110
// Deallocating negative ID or ID that was never allocated
110-
expect(() => manager.deallocate(0 as any)).toThrow(/valid entity|deallocate/i);
111+
expect(() => manager.deallocate(0 as unknown as ReturnType<typeof manager.allocate>)).toThrow(
112+
/valid entity|deallocate/i,
113+
);
111114
});
112115

113116
it("should serialize and deserialize state", () => {
114117
const manager = new EntityIdManager();
115118

116119
const id1 = manager.allocate();
117-
const id2 = manager.allocate();
120+
manager.allocate();
118121

119122
manager.deallocate(id1);
120123

@@ -138,7 +141,7 @@ describe("EntityIdManager", () => {
138141

139142
const id1 = manager.allocate();
140143
const id2 = manager.allocate();
141-
const id3 = manager.allocate();
144+
manager.allocate();
142145

143146
manager.deallocate(id1);
144147
manager.deallocate(id2);
@@ -149,6 +152,6 @@ describe("EntityIdManager", () => {
149152

150153
// Next allocation should be a new ID
151154
const newId = manager.allocate();
152-
expect(newId).toBe(id3 + 1);
155+
expect(Number(newId as unknown as number)).toBe(1027);
153156
});
154157
});

src/__tests__/serialization-bounds.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("Serialization edge cases", () => {
1111
expect(snapshot.version).toBeDefined();
1212

1313
const newWorld = new World(snapshot);
14-
expect(newWorld.exists(-1)).toBe(false);
14+
expect(newWorld.exists(-1 as unknown as ReturnType<typeof world.new>)).toBe(false);
1515
});
1616

1717
it("should serialize and deserialize single entity", () => {

src/__tests__/testing.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, expect, it } from "bun:test";
2-
import { component, relation, type EntityId } from "../core/entity";
2+
import { component, relation, type ComponentId } from "../core/entity";
33
import { World } from "../core/world";
44
import {
55
AssertionError,
@@ -15,11 +15,11 @@ type Position = { x: number; y: number };
1515
type Velocity = { x: number; y: number };
1616
type Health = { current: number; max: number };
1717

18-
let PositionId: EntityId<Position>;
19-
let VelocityId: EntityId<Velocity>;
20-
let HealthId: EntityId<Health>;
21-
let TagId: EntityId<void>;
22-
let ParentId: EntityId<{ offset: { x: number; y: number } }>;
18+
let PositionId: ComponentId<Position>;
19+
let VelocityId: ComponentId<Velocity>;
20+
let HealthId: ComponentId<Health>;
21+
let TagId: ComponentId<void>;
22+
let ParentId: ComponentId<{ offset: { x: number; y: number } }>;
2323

2424
describe("testing module", () => {
2525
beforeEach(() => {

src/__tests__/wildcard-relation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe("Wildcard relation edge cases", () => {
5252

5353
// Verify structure
5454
for (const [target, data] of results) {
55-
expect(targets).toContain(target);
55+
expect(targets).toContain(target as any);
5656
expect(data.strength).toBeGreaterThanOrEqual(0);
5757
expect(data.strength).toBeLessThan(100);
5858
}

src/__tests__/world-component-management.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { beforeEach, describe, expect, it } from "bun:test";
2-
import { component, createEntityId, relation, type EntityId } from "../core/entity";
2+
import { component, createEntityId, relation, type ComponentId, type EntityId } from "../core/entity";
33
import { World } from "../core/world";
44

55
describe("World - Component Management", () => {
66
type Position = { x: number; y: number };
77
type Velocity = { x: number; y: number };
88

9-
let positionComponent: EntityId<Position>;
10-
let velocityComponent: EntityId<Velocity>;
9+
let positionComponent: ComponentId<Position>;
10+
let velocityComponent: ComponentId<Velocity>;
1111

1212
beforeEach(() => {
1313
positionComponent = component<Position>();

0 commit comments

Comments
 (0)