microsoft / microsoft/TypeScript

Have QuickInfo use import types to display type aliases that are not in scope

Open
#23,642 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Domain: LS: Quick Info Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

Search Terms:
type alias, import, display, quickinfo, intellisense

Code

// @Filename: file1.ts
export type ComplicatedType<T, U> = { [K in Exclude<keyof T, U>]: T[K] } // could be anything here
export declare function getComplicatedType<T, U extends keyof T>(arg: T, exclude: U): ComplicatedType<T, U>

// @Filename: file2.ts
import { getComplicatedType } from "./file1"
interface SomeInterface {
    a: string
    b<T>(arg: T): T,
    c: { c2: string } | { c3: number },
    d?: boolean
}
declare const test: SomeInterface
const result = getComplicatedType(test, "a") // quickinfo on result currently displays something like:
/* const result: {
    b: <T>(arg: T) => T;
    c: {
        c2: string;
    } | {
        c3: number;
    };
    d: boolean | undefined;
} */

Current behavior:
The quick info type shown for result is a fully expanded anonymous type because ComplicatedType is not in scope in file2. Importing ComplicatedType in file2 makes quick info display const result: ComplicatedType<SomeInterface, "a">, but I don't think it's common to import a type alias purely for the quick info benefit if it isn't actually used anywhere in the file.

While the example above isn't that bad, in some cases (#18754, #23458) the fully expanded types can be so large that they actually cause a performance issue for the language service.

Suggested behavior:
Use import types from #22592 to display an accurate qualified reference to ComplicatedType. So in the example above quick info for result could instead display something like:

const result: import("./file1").ComplicatedType<SomeInterface, "a">

Which, although a little verbose, would be much more readable than many fully expanded types.

Related Issues:
#22592 added import types.

#18754, #23458, #6070, #13095 - Various issues related to the display of types.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the file1.ts/file2.ts repro and the QuickInfo behavior described in the issue; review import types from issue #22592 and the related type-display issues. Done means QuickInfo can show a qualified import-type reference such as import("./file1").ComplicatedType<SomeInterface, "a"> instead of expanding the alias.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.