Skip to content

Comments

Improve formatting for constraints on type parameters#14858

Merged
fisker merged 4 commits intoprettier:mainfrom
sosukesuzuki:fix-14809
May 26, 2023
Merged

Improve formatting for constraints on type parameters#14858
fisker merged 4 commits intoprettier:mainfrom
sosukesuzuki:fix-14809

Conversation

@sosukesuzuki
Copy link
Contributor

@sosukesuzuki sosukesuzuki commented May 25, 2023

Description

Fixes #14809
Fixes #14808

It uses the same logic as the "fluid" layout of the assignment.
This changes some behavior that is not related to the original issue, such as the lineSuffixBoundary comment.

Checklist

  • 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/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

Comment on lines +176 to +182
const groupId = Symbol("constraint");
parts.push(
" extends",
group(indent(line), { id: groupId }),
lineSuffixBoundary,
indentIfBreak(print("constraint"), { groupId })
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

case "fluid": {
const groupId = Symbol("assignment");
return group([
group(leftDoc),
operator,
group(indent(line), { id: groupId }),
lineSuffixBoundary,
indentIfBreak(rightDoc, { groupId }),
]);
}

LongerLongerLongerLongerInnerType extends
LongerLongerLongerLongerLongerLo | ngerLongerLongerOtherType,
| LongerLongerLongerLongerLongerLo
| ngerLongerLongerOtherType,
Copy link
Member

Choose a reason for hiding this comment

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

Should we keep the extends part inline?

Prettier pr-14858
Playground link

--parser typescript

Input:

export type OuterType4<
  LongerLongerLongerLongerInnerTypeLongerLongerLongerLongerInnerType extends
    A | B,
> = { a: 1 };

Output:

export type OuterType4<
  LongerLongerLongerLongerInnerTypeLongerLongerLongerLongerInnerType extends
    | A
    | B,
> = { a: 1 };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, yes? But current main outputs this code, so if we address this, it should be addressed as other issue.

Prettier 2.8.8
Playground link

--parser typescript

Input:

export type OuterType4<
  LongerLongerLongerLongerInnerTypeLongerLongerLongerLongerInnerType extends
    A | B,
> = { a: 1 };

Output:

export type OuterType4<
  LongerLongerLongerLongerInnerTypeLongerLongerLongerLongerInnerType extends
    | A
    | B
> = { a: 1 };

Copy link
Member

@fisker fisker May 25, 2023

Choose a reason for hiding this comment

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

But we changed output of this test.(line 407 in this file) The original didn't break things after extends.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think that should be a concern here. Because "original" means current main branch and there is no change from the 2.8.8 behavior. So this is a different issue.

@fisker fisker merged commit 6cff214 into prettier:main May 26, 2023
@fisker
Copy link
Member

fisker commented May 26, 2023

I'll release a new alpha version.

@fisker
Copy link
Member

fisker commented May 26, 2023

[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in v3 (2) Regression in v3

2 participants