-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Fix/indexed access type hover #62677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves the hover display for indexed access types by showing resolved types (e.g., number) instead of the indexed access expression (e.g., Scalars["Number"]). This enhancement makes type information in tooltips more readable and immediately useful to developers.
Key changes:
- Modified type-to-node conversion logic to expand type aliases when generating object type literals
- Added a new fourslash test to verify the hover behavior for indexed access types with generics
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/cases/fourslash/quickInfoIndexedAccessWithGeneric.ts | Adds test cases verifying that indexed access types display as resolved types in hover tooltips |
| src/compiler/checker.ts | Updates type conversion logic to expand aliases and prefer resolved types in object type literal contexts |
src/compiler/checker.ts
Outdated
| // When in an object type literal context, expand type aliases to show resolved types | ||
| // for better clarity in hover information and quick info |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment describes expanding type aliases but the actual condition checks for !(context.flags & NodeBuilderFlags.InObjectTypeLiteral) which means the expansion is avoided when in object type literal context. The comment should clarify that type aliases are expanded unless we're in an object type literal context, or the logic may be inverted from the intended behavior.
| // When in an object type literal context, expand type aliases to show resolved types | |
| // for better clarity in hover information and quick info | |
| // Expand type aliases to show resolved types for better clarity in hover information and quick info, | |
| // unless we're in an object type literal context. |
src/compiler/checker.ts
Outdated
| // When in an object type literal context, prefer the resolved type over the syntactic form | ||
| // to ensure indexed access types and generic type aliases are properly resolved |
Copilot
AI
Oct 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment states we prefer resolved types when in object type literal context, but the code condition !(context.flags & NodeBuilderFlags.InObjectTypeLiteral) means the syntactic form is avoided when we're NOT in object type literal context. The comment contradicts the code logic.
| // When in an object type literal context, prefer the resolved type over the syntactic form | |
| // to ensure indexed access types and generic type aliases are properly resolved | |
| // When NOT in an object type literal context, prefer the syntactic form over the resolved type | |
| // to preserve original type annotations where possible |
|
@microsoft-github-policy-service agree |
|
Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page. Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up. |
Fixes #62608
Summary
This PR fixes the hover display for indexed access types to show the resolved type instead of the indexed access expression when appropriate. This improves developer experience by displaying more readable and useful type information in quick info tooltips.
Problem
When hovering over types that use indexed access (e.g.,
Scalars["Number"]), TypeScript would display the indexed access expression instead of the resolved type (number). This made it harder to understand what types properties actually resolve to, especially when combined with union types likeScalars["Number"] | null.Solution
Modified the
typeToTypeNodeHelperfunction insrc/compiler/utilities.tsto resolve indexed access types before converting them to type nodes when generating quick info. This ensures that hover tooltips display the simplified, resolved types rather than the complex indexed access expressions.Changes Made
typeToTypeNodeHelperto check if a type is an indexed access typeBefore and After
Before
After
Notes
This change only affects the display of types in hover tooltips and does not change the actual type checking behavior or runtime code generation.