Repository navigation
obj["name"] of a class with a string indexer calls its get/set - #799
Merged
Merged
Conversation
A class that declares `[key: string]: T` with get/set could be indexed only with a key that isn't a constant: `bag["name"]`, and `const k = "name"; bag[k]`, were read as the member `name` and failed with "can't resolve property/field/base 'name'". A constant key now goes to the indexer when it names no member of the class or a base class; a key that names a field, method, accessor or static member is still that member, as in TypeScript. This lets the default library's JsonValue (get/set by key) take `value["name"]` and `value["name"] = member`. Tests: 00class_indexer_string_key.ts (literal, const and let keys, writes, member names that win, one from a base class) under gc, rc, none and own, and export_/import_class_string_indexer.ts across a shared library under gc, rc and own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 9, 2026
ASDAlexander77
added a commit
that referenced
this pull request
Nov 9, 2026
…et (#800) #799 sent a constant string key to a class's indexer only when the indexer's key was `string`. With `[key: number | string]: T`, `table[0]` and variable keys reached get/set, but `table["name"]` was still read as the member `name` and failed with "can't resolve property/field/base 'name'". A union key that takes a string now counts as well. A key that names a member is still that member. This lets the default library's JsonValue take `value["name"]` and `value[0]` through one indexer. Test: 00class_indexer_union_key.ts (string and number keys reaching the same items, constant and variable keys of both kinds, a member name that wins) under gc, rc, none and own. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
A class that declares
[key: string]: Twithget/setcould be indexed only with a key that isn't a constant.bag["name"], andconst k = "name"; bag[k], were read as the membernameand failed with "can't resolve property/field/base 'name'" (the// TODO: implement '[string]' access hereinmlirGenElementAccess).A constant key now goes to the indexer when it names no member of the class or of a base class. A key that names a field, method, accessor or static member is still that member, as in TypeScript.
This lets the default library's
JsonValue(get/set by key) takevalue["name"]andvalue["name"] = member. The DefaultLib change follows once this is merged.Tests
00class_indexer_string_key.ts: literal,constandletkeys, writes, and member names that win (one from a base class). Runs under gc, rc, none and own.export_class_string_indexer.ts/import_class_string_indexer.ts: the same across a shared library, under gc, rc and own.Not in this PR
Under
-mm=own, two writes by key to the default library'sJsonValue(person[a] = …; person[b] = …,setdeclared@lends("this") @keeps("value")) crash tslang.exe when building the exe. It happens onorigin/mainwithout this change, also withletkeys, and not with direct.set()calls or with a test class of the same shape, in one file or across a shared library. It needs its own fix.🤖 Generated with Claude Code