Skip to content

Ugly formatting of nested conditional types in TypeScriptΒ #7940

@typeofweb

Description

@typeofweb

Prettier 2.0.2
Playground link

--parser typescript
--print-width 100
--trailing-comma all

Input:

type TypeName<T> =
  T extends string ? "string" :
  T extends number ? "number" :
  T extends boolean ? "boolean" :
  T extends undefined ? "undefined" :
  T extends Function ? "function" :
  T extends Array<any> ? "array" :
  T extends null ? "null" :
  T extends symbol ? "symbol" :
  "object";

Output:

type TypeName<T> = T extends string
  ? "string"
  : T extends number
  ? "number"
  : T extends boolean
  ? "boolean"
  : T extends undefined
  ? "undefined"
  : T extends Function
  ? "function"
  : T extends Array<any>
  ? "array"
  : T extends null
  ? "null"
  : T extends symbol
  ? "symbol"
  : "object";

Expected behavior:

Keep the original formatting which is much nicer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions