Skip to content

Conversation

@TudorGR
Copy link

@TudorGR TudorGR commented Oct 26, 2025

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 like Scalars["Number"] | null.

Solution

Modified the typeToTypeNodeHelper function in src/compiler/utilities.ts to 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

  • Updated typeToTypeNodeHelper to check if a type is an indexed access type
  • Added logic to resolve the indexed access type to its actual type
  • Applied the resolution when appropriate for better readability in hover tooltips

Before and After

Before

Screenshot 2025-10-26 at 15 40 04

After

Screenshot 2025-10-26 at 15 47 24

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.

Copilot AI review requested due to automatic review settings October 26, 2025 13:50
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Oct 26, 2025
@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug labels Oct 26, 2025
Copy link

Copilot AI left a 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

Comment on lines 6845 to 6846
// When in an object type literal context, expand type aliases to show resolved types
// for better clarity in hover information and quick info
Copy link

Copilot AI Oct 26, 2025

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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
Comment on lines 9033 to 9034
// 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
Copy link

Copilot AI Oct 26, 2025

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.

Suggested change
// 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

Copilot uses AI. Check for mistakes.
@TudorGR
Copy link
Author

TudorGR commented Oct 26, 2025

@microsoft-github-policy-service agree

@typescript-bot
Copy link
Collaborator

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.

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: Not started

Development

Successfully merging this pull request may close these issues.

Typescript Type Resolution Fails with generics of T | null

2 participants