TypeScript: Fix formatting of type operators as arrow function…#6901
TypeScript: Fix formatting of type operators as arrow function…#6901lydell merged 7 commits intoprettier:masterfrom
Conversation
| grandparent.type === "TSTypeAnnotation" && | ||
| n[paramsKey][0].type !== "TSUnionType" && | ||
| n[paramsKey][0].type !== "UnionTypeAnnotation" && | ||
| n[paramsKey][0].type !== "TSIntersectionType" && |
There was a problem hiding this comment.
These conditions currently catch two different situations:
- Variable declarations with generic type annotations:
const a: Type<Params> = value;like the second and third code samples in No line break for type annotations in variable declarations exceeding 80 characters #6899. - Variable declarations initialized with an arrow function, for which a generic return type is specified:
const a = (params): Type<Params> => {}like Unexpected formatting of a return type in TypeScript #6886 and the first code sample in No line break for type annotations in variable declarations exceeding 80 characters #6899.
I think the right thing to do here is to exclude the situation # 2, completely or at least when the arrow function has parameters (because the parameters can break the line). I think when you made #6467, you didn't keep the situation # 2 in mind at all, did you?
There was a problem hiding this comment.
You're right. Sorry, I didn't keep the situation # 2 in mind when I created #6467. I pushed commits to exclude the situation # 2.
| greatGreatGrandParent.type === "VariableDeclarator" && | ||
| grandparent && | ||
| grandparent.type === "TSTypeAnnotation" && | ||
| greatGrandParent && |
There was a problem hiding this comment.
We've already checked that greatGreatGrandParent exists, so no need to check if grandparent and greatGrandParent exist.
|
Can you shorten the changelog entry? Also, the “before” (“stable”) example should come before the “after” (“master”) example – you seem to have mixed those up. |
* 'master' of github.com:prettier/prettier: Don't lowercase element names in CSS selectors (#6947) Support string-to-package config in JSON schema: (#6941) Rename SECURITY.md to .github/SECURITY.md Create SECURITY.md Add the XML plugin to the docs (#6944) TypeScript: Fix formatting of type operators as arrow function… (#6901) SCSS: don't add extra comma after last comment in map (#6918) Remove typescript-etw from build (#6919)
A non-essential workaround for #6899
docs/directory)changelog_unreleased/*/pr-XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨