feat(tilemap): typed ObjectLayer schema — ObjectKind + generic accessors (B2, D3)#157
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
B2 — typed ObjectLayer schema (v0.14 wave 1, D3)
Opt-in, type-safe object-layer API. Fully additive — untyped usage and
query()are unchanged.ObjectKindis now anas constobject (enum-style DX, wire-compatible with Tiled strings, no TS enum);TileMapObjectKindkept as a structural alias.ObjectLayer<S extends ObjectSchema = ObjectSchema>with typed accessors:byType(type)(propertiestyped asS[type]),byKind(kind)(narrowed by the geometry discriminant),where(type, predicate). Default type param reproduces the old untyped behaviour, sogetObjectLayer('x')keeps working.getObjectLayer<S>(name)threads the schema type param through.Schema is a developer promise (Tiled data is untyped at runtime, no runtime validation — documented). Runtime +
expectTypeOfcompile-time tests added.Verification (local, all green)
tilemap+tiled typecheck · test suite (3370 passed) · lint:packages · format:check · docs:api:check (in sync)