Ugly formatting of nested conditional types in TypeScript
See original GitHub issuePrettier 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:50
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Evaluation of Nested Conditional Type - Stack Overflow
The conditional type you've got here, type OrganizationPayload<TR extends string | null = string | null> = { id: number districtAdmin?:
Read more >Google TypeScript Style Guide
TypeScript expresses information in types, so names should not be decorated with information that is included in the type. (See also Testing Blog...
Read more >Advanced TypeScript: The ultimate Tailwind typings
This post is about implementing utilities for the ultimate Tailwind-React ergonomics and typings for it. In the process, we'll learn about ...
Read more >Are chain ternary operators an antipattern? : r/reactjs - Reddit
In JavaScript the ternary operators are parsed right-to-left, ... Also, nested ternaries if formatted flat and well considered are totally ...
Read more >Pandoc User's Guide
Pandoc is a Haskell library for converting from one markup format to another, ... Thus, to convert hello.txt from Markdown to LaTeX, you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we should improve it
Prettier 2.2.1 Playground link
Input:
Output:
Expected behavior: At least keep the parentheses around
NodeOrToken extends TSESTree.Node ? AST_NODE_TYPES : AST_TOKEN_TYPES