Skip to content

Typescript Quick Info Formatter Removes parentheses () from declared type on hovering, for conditionally inferring types #48729

Closed
@ajitjha393

Description

@ajitjha393

Bug Report

Typescript Language Formatter function removes parentheses () from the declared type on hovering over it.
Not a bug with the Typescript parser itself.

🔎 Search Terms

infer, conditional typing, parentheses, hover

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about parentheses getting removed for conditionally inferring types

⏯ Playground Link

Playground link with relevant code

💻 Code

image

type Tail<T extends any[]> = ((...t: T) => void) extends (
  h: any,
  ...rest: infer R
) => void
  ? R
  : never;

🙁 Actual behavior

Wrapped () gets removed on hovering from the declared conditional inferring type.
Because of this the hovered type shown is not the same as the declared type and they are not interchangeable and can cause bugs.

Without parenthesis, the TS parses it as a Type which returns a Function and the return type of the function is that conditional "void extends ..." which is not what was declared.

Example -
image

🙂 Expected behavior

() should be preserved and shown while hovering so to prevent the errors that can arise because of missing () in the conditional inferring types

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions