Skip to content

feat(tilemap): typed ObjectLayer schema — ObjectKind + generic accessors (B2, D3)#157

Merged
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b2-objectlayer
Jun 22, 2026
Merged

feat(tilemap): typed ObjectLayer schema — ObjectKind + generic accessors (B2, D3)#157
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b2-objectlayer

Conversation

@Exoridus

Copy link
Copy Markdown
Owner

B2 — typed ObjectLayer schema (v0.14 wave 1, D3)

Opt-in, type-safe object-layer API. Fully additive — untyped usage and query() are unchanged.

  • ObjectKind is now an as const object (enum-style DX, wire-compatible with Tiled strings, no TS enum); TileMapObjectKind kept as a structural alias.
  • ObjectLayer<S extends ObjectSchema = ObjectSchema> with typed accessors: byType(type) (properties typed as S[type]), byKind(kind) (narrowed by the geometry discriminant), where(type, predicate). Default type param reproduces the old untyped behaviour, so getObjectLayer('x') keeps working.
  • getObjectLayer<S>(name) threads the schema type param through.
interface LevelObjects { spawn: { team: 'red' | 'blue' }; pickup: { item: 'coin'; amount: number } }
const e = map.getObjectLayer<LevelObjects>('Entities');
e.byType('spawn')[0].properties.team;        // 'red' | 'blue'
e.byKind(ObjectKind.Polygon);
e.where('pickup', o => o.properties.amount > 5);

Schema is a developer promise (Tiled data is untyped at runtime, no runtime validation — documented). Runtime + expectTypeOf compile-time tests added.

Verification (local, all green)

tilemap+tiled typecheck · test suite (3370 passed) · lint:packages · format:check · docs:api:check (in sync)

…ors (B2, D3)

Adds an opt-in, type-safe object-layer API. Fully additive: untyped usage and
query() are unchanged.

- `ObjectKind` is now an `as const` object (enum-style DX, wire-compatible with
  Tiled strings, no TS enum); `TileMapObjectKind` kept as a structural alias.
- `ObjectLayer<S extends ObjectSchema = ObjectSchema>` with typed accessors:
  `byType(type)` (properties typed as `S[type]`), `byKind(kind)` (narrowed by the
  geometry discriminant), and `where(type, predicate)`. The default type param
  reproduces the old untyped behaviour, so `getObjectLayer('x')` keeps working.
- `getObjectLayer<S>(name)` threads the schema type param through.

The schema is a developer promise — Tiled data is untyped at runtime, no runtime
validation (documented). Runtime + expectTypeOf compile-time tests added; per-file
eslint override for the PascalCase `as const` members. API docs regenerated.
@Exoridus Exoridus merged commit 5c9fc7d into main Jun 22, 2026
12 checks passed
@Exoridus Exoridus deleted the feat/v0.14-b2-objectlayer branch June 22, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant