Skip to content

ecs: allow Map and Set resources with a default, and symbol-keyed maps #247

Closed

Description

@krisnye

Summary

Declaring a resource of type Map or Set is narrow: ReadonlyMap<symbol, unknown> and Resource.Key are rejected ("keyof isn't a declared type"), and a ReadonlySet takes no default.

Case (mecs, @adobe/ecs 0.2.4)

History keeps a note of the values it wrote when it applied an undo/redo, so the finalizer that records resource changes skips them. It is a set of strings ("<index>=<json>"), declared as ReadonlySet<string> with no default; we had wanted ReadonlyMap<Resource.Key, unknown> (key to value) and a default: new Set().

`keyof` isn't a declared type   (for the Resource.Key / symbol key)
default isn't of its declared type   (for the Set)

We worked around it by encoding keys and values in a string.

Requested

Allow Map/Set (readonly) with a default of the same type, and allow a symbol-typed map key, or document the limits of declared types and why.

Activity

  1. krisnye commented on Nov 1, 2026

    @krisnye
    CollaboratorAuthor

    Addressed in #250 (Adobe-Firefly/ecs#9), with one correction to the premise: a ReadonlySet or ReadonlyMap resource needs no default. It starts empty in each world. Giving it one now says "…which starts empty in each world: leave its default out".

    A set or map of what isn't data now registers as a value that isn't data, still starting empty in each world. That covers a symbol, Resource.Key or Component.Key, a class, or unknown, so ReadonlyMap<Resource.Key, unknown> works. Symbol keys stay out of data: data crosses threads by structured clone, which refuses symbols, and is saved by schema. So such a map stays on the world's thread and isn't persisted, which suits the history's note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions