Skip to content

Preserve error elaboration for indexed access type assignments#63278

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

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

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

Labels

None yet

Projects

Status: Not started

1 participant