Skip to content

Allow customization of type display format in hover tooltipsΒ #59370

Open
@lsby

Description

@lsby

πŸ” Search Terms

  • customization type display
  • Array or T[]

βœ… Viability Checklist

⭐ Suggestion

In TypeScript, when hovering over a variable, the inferred type is displayed in a specific format.
For instance, an array of numbers is shown as number[].
However, some developers, including myself, prefer the alternative format Array<number> for readability and consistency with other generic types.

πŸ“ƒ Motivating Example

I have noticed that there is an WriteArrayAsGenericType flag in the Abstract Syntax Tree (AST) that can convert T[] to Array<T>.

I would like to request the addition of a configuration option in tsconfig.json to enable this flag, allowing developers to choose their preferred format for array types in hover tooltips.

For example:

{
  "compilerOptions": {
    "typeDisplayFormat": "generic" // Options could be "generic" for Array<number> or "shorthand" for number[]
  }
}

πŸ’» Use Cases

Complex Type Readability: I frequently write functional code that can lead to complex types like Task<Maybe<Task<Maybe<T[]>>[]>>[]. The shorthand [] notation can make it difficult to understand the nested generic relationships. Displaying these types as Array<T> would significantly improve readability and comprehension.

Consistency: Most other generic types use angle brackets (e.g., Promise<T>, Map<K, V>), and only array types use the special shorthand (number[]). Aligning array types with this convention would ensure consistency across all types and improve clarity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions