-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
TypeScript: Fix formatting of type operators as arrow function… #6901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
src/language-js/printer-estree.js
Outdated
| greatGreatGrandParent.type === "VariableDeclarator" && | ||
| grandparent && | ||
| grandparent.type === "TSTypeAnnotation" && | ||
| greatGrandParent && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've already checked that greatGreatGrandParent exists, so no need to check if grandparent and greatGrandParent exist.
alexander-akait
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
|
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✨