Skip to content

Fix #30408: Fallback to string index signature for literal and generic indexing#62925

Closed
mhughes2012 wants to merge 3 commits intomicrosoft:mainfrom
mhughes2012:fix-index-signature-fallback-30408
Closed

Fix #30408: Fallback to string index signature for literal and generic indexing#62925
mhughes2012 wants to merge 3 commits intomicrosoft:mainfrom
mhughes2012:fix-index-signature-fallback-30408

Conversation

@mhughes2012
Copy link
Copy Markdown

Fixes #30408

Description

This PR addresses issue #30408 where indexing an object with a string literal or a generic type parameter constrained to string would fail to fall back to an available string index signature if a specific property was not found. This often resulted in any types or confusing "property missing" errors even when a valid index signature existed.

The change modifies the property lookup logic in src/compiler/checker.ts to:

  1. First, check for a specific named property (preserving existing priority).
  2. Second, if no specific property is found, check if the index type is assignable to string.
  3. If assignable, attempt to resolve the type via the string index signature.

Checklist

  • There is an associated issue in the Backlog milestone
  • Code is up-to-date with the main branch
  • You've successfully run hereby runtests locally
  • There are new or updated unit tests validating the change

Test Case

I have added a new compiler test case tests/cases/compiler/stringLiteralIndexingWithIndexSignature.ts which validates:

  • Literal indexing on a type with a string index signature.
  • Generic indexing (K extends string) correctly resolving to the index signature's type.
  • Verification that reference baselines correctly capture these inferred types.

…nd generic indexing

Ensure that string literal indexing and type parameters constrained to string
correctly fall back to an available string index signature if a specific
property is not found. This prevents confusing 'any' or 'missing property'
errors when a valid indexer exists.
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Dec 24, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Dec 24, 2025
@mhughes2012
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

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

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Confusing error message for labels used before definition

2 participants