Skip to content

Preserve error elaboration for indexed access type assignments#63278

Closed
WhiteMinds wants to merge 1 commit intomicrosoft:mainfrom
WhiteMinds:fix/improve-indexed-access-error-elaboration
Closed

Preserve error elaboration for indexed access type assignments#63278
WhiteMinds wants to merge 1 commit intomicrosoft:mainfrom
WhiteMinds:fix/improve-indexed-access-error-elaboration

Conversation

@WhiteMinds
Copy link

Fixes #63206

When assigning to an indexed access type (e.g. this["faa"]), the checker resolves the constraint and performs a structural comparison that generates specific error messages (missing properties, type mismatches, etc.). However, reportRelationError unconditionally clears errorInfo before reporting the generic "could be instantiated with an arbitrary type" message, discarding the useful elaboration.

This change preserves errorInfo when the target is an IndexedAccess type, so users see both the generic message and the specific details.

Before

this.foo = {}
// Type '{}' is not assignable to type 'this["faa"]'.
//   'this["faa"]' could be instantiated with an arbitrary type which could be unrelated to '{}'.

After

this.foo = {}
// Type '{}' is not assignable to type 'this["faa"]'.
//   'this["faa"]' could be instantiated with an arbitrary type which could be unrelated to '{}'.
//     Property 'key' is missing in type '{}' but required in type '{ key: number | null; }'.

this.foo = {key: "str"}
// Type '{ key: string; }' is not assignable to type 'this["faa"]'.
//   'this["faa"]' could be instantiated with an arbitrary type which could be unrelated to '{ key: string; }'.
//     Type '{ key: string; }' is not assignable to type '{ key: number | null; }'.
//       Types of property 'key' are incompatible.
//         Type 'string' is not assignable to type 'number'.

Two existing baselines updated to reflect the additional elaboration (no errors removed, only more specific detail added).

When assigning to an indexed access type like this["faa"], the checker
resolves the constraint and performs a structural comparison that
generates specific error messages (e.g., missing properties or type
mismatches). However, reportRelationError unconditionally clears
errorInfo before reporting the generic "could be instantiated with an
arbitrary type" message, discarding the useful elaboration.

This change preserves errorInfo when the target is an IndexedAccess
type, so users see both the generic message and the specific details
about what went wrong (e.g., "Property 'key' is missing" or "Types of
property 'key' are incompatible").

Fixes microsoft#63206
@WhiteMinds WhiteMinds force-pushed the fix/improve-indexed-access-error-elaboration branch from f2412fa to 6031cbb Compare March 21, 2026 06:55
@WhiteMinds
Copy link
Author

@microsoft-github-policy-service agree

@typescript-bot
Copy link
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

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

2 participants