Skip to content

obj["name"] of a class with a number | string indexer calls its get/set - #800

Merged
ASDAlexander77 merged 1 commit into
mainfrom
class-union-indexer
Nov 9, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
class-union-indexer

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

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 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 of the class or a base class is still that member.

This lets the default library's JsonValue take value["name"] and value[0] through one indexer (TypeScriptCompilerDefaultLib, branch json-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.
  • Full Release suite locally: 6868 of 6868 passed.

🤖 Generated with Claude Code

#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>
@ASDAlexander77
ASDAlexander77 merged commit 14bc9e0 into main Nov 9, 2026
11 of 12 checks passed
@ASDAlexander77
ASDAlexander77 deleted the class-union-indexer branch November 9, 2026 20:12
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