Skip to content

ObjectDictionary<T>: the value of a string index signature - #114

Merged
ASDAlexander77 merged 1 commit into
mainfrom
object-dictionary
Nov 21, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
object-dictionary

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

The compiler is about to map a string index signature, { [key: string]: T }, and an object literal with a key known only at run time ({ [m]: v }), to a dictionary. This is that dictionary.

  • ObjectDictionary<T> (@dictionary), in lib.generics.ts: entries by key in the order they were added.
    • get returns T | undefined: undefined for a key it does not hold.
    • set writes a value; writing undefined deletes the entry.
    • has, delete, keys and size.
    • It keeps its own copies of the keys, so a caller's key is not moved under -mm=own.
    • Under -mm=own it owns its values: a value written in moves in, a read borrows, and a value overwritten or deleted is dropped.
  • With the new compiler, d.name, d["name"] and d[k] from outside the class always mean entries, never its members. The @dictionary decorator marks the class for that.
  • objectDictionaryAssign<T>(target, source) is for a spread of a dictionary into a new one. It is a function, not a member, so it is only made for the types it is used with. Under own, a dictionary of objects (which can't be copied) fails only where one is spread.
  • Test: tests/object_dictionary.ts. Its first line skips -mm=own until a released compiler has the companion own fix: a parameter moved on paths that exclude each other, which set needs. The test uses only d[k], so it runs the same with the released compiler and the new one.

Companion compiler PR to follow; this one goes in first.

🤖 Generated with Claude Code

…y run-time keys (the compiler maps { [key: string]: T } to it), and objectDictionaryAssign for a spread of one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 665603d into main Nov 21, 2026
10 checks passed
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