Repository navigation
obj["name"] of a class with a number | string indexer calls its get/set - #800
Merged
Merged
Conversation
#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
Follow-up to #799. That change 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 reachedget/set, buttable["name"]was still read as the membernameand 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 of the class or a base class is still that member.
This lets the default library's
JsonValuetakevalue["name"]andvalue[0]through one indexer (TypeScriptCompilerDefaultLib, branchjson-index-access).Tests
00class_indexer_union_key.ts: string and number keys reaching the same items, constant and variable keys of both kinds, and a member name that wins. Runs under gc, rc, none and own.🤖 Generated with Claude Code