Skip to content

Conversation

@sosukesuzuki
Copy link
Contributor

@sosukesuzuki sosukesuzuki commented Nov 9, 2019

A non-essential workaround for #6899

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory)
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/pr-XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

@sosukesuzuki sosukesuzuki requested a review from thorn0 November 9, 2019 15:28
grandparent.type === "TSTypeAnnotation" &&
n[paramsKey][0].type !== "TSUnionType" &&
n[paramsKey][0].type !== "UnionTypeAnnotation" &&
n[paramsKey][0].type !== "TSIntersectionType" &&
Copy link
Member

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:

  1. 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.
  2. 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?

Copy link
Contributor Author

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.

greatGreatGrandParent.type === "VariableDeclarator" &&
grandparent &&
grandparent.type === "TSTypeAnnotation" &&
greatGrandParent &&
Copy link
Member

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.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

@lydell
Copy link
Member

lydell commented Nov 11, 2019

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.

@lydell lydell changed the title TypeScript: Fix formatting of type operators as arrow function return type TypeScript: Fix formatting of type operators as arrow function… Nov 12, 2019
@lydell lydell merged commit 9b37dca into prettier:master Nov 12, 2019
@sosukesuzuki sosukesuzuki deleted the fix-6899 branch November 13, 2019 01:31
lipis added a commit that referenced this pull request Jan 8, 2020
* '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)
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 11, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants