Skip to content

Incorrect removal of parentheses when using an infer with a constraint in a function predicate #14275

@bradzacher

Description

@bradzacher

Prettier 2.8.3
Playground link

--parser typescript

Input:

type Test<T> = T extends ((
  token: TSESTree.Token
) => token is infer U extends TSESTree.Token)
  ? U
  : TSESTree.Token;

Output:

type Test<T> = T extends (
  token: TSESTree.Token
) => token is infer U extends TSESTree.Token
  ? U
  : TSESTree.Token;

Expected behavior:
The parentheses should be retained as they are required.
Without the parentheses it causes a syntax error:

SyntaxError: '?' expected. (5:19)
  3 | ) => token is infer U extends TSESTree.Token
  4 |   ? U
> 5 |   : TSESTree.Token;
    |                   ^
  6 |

Metadata

Metadata

Assignees

Labels

lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions