Skip to content

Refactor interface body and object type print#14111

Merged
fisker merged 19 commits intoprettier:mainfrom
fisker:ts-interface-body
Oct 22, 2025
Merged

Refactor interface body and object type print#14111
fisker merged 19 commits intoprettier:mainfrom
fisker:ts-interface-body

Conversation

@fisker
Copy link
Copy Markdown
Member

@fisker fisker commented Jan 5, 2023

Description

TSInterfaceBody should use the same logic as ClassBody.

To fix #14040, we can introduce similar logic as shouldPrintSemicolonAfterClassProperty after this get merged.

//cc @thorn0

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

@fisker fisker marked this pull request as ready for review January 5, 2023 06:49
@thorn0
Copy link
Copy Markdown
Member

thorn0 commented Jan 7, 2023

Interface bodies and object types are exactly the same syntax (interfaces essentially are named object types), so #14040 is a bug in object types too (playground), and using different code paths to print them is probably not the right thing to do.

@fisker
Copy link
Copy Markdown
Member Author

fisker commented Jan 9, 2023

I noticed TSTypeLiteral, but I don't know they are the same, I was planning to check it later.

@fisker
Copy link
Copy Markdown
Member Author

fisker commented Jan 9, 2023

It seems we always break TSInterfaceBody into multi lines, but not TSTypeLiteral.

bar /* foo */ /* bar */?(/* baz */) /* bat */;
bar2 /* foo */(/* baz */) /* bat */;
bar /* foo */ /* bar */?(/* baz */); /* bat */
bar2 /* foo */(/* baz */); /* bat */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this change in the output intended?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so,

Prettier 2.8.2
Playground link

--parser typescript

Input:

interface foo1 {
  bar /* bat */;
  bar ;/* bat */
}

class foo1 {
  bar /* bat */;
  bar ;/* bat */
}

Output:

interface foo1 {
  bar /* bat */;
  bar /* bat */;
}

class foo1 {
  bar /* bat */;
  bar; /* bat */
}

@fisker fisker changed the base branch from next to main April 23, 2023 01:21
@fisker fisker force-pushed the ts-interface-body branch from 86cba63 to d5cdaf7 Compare October 21, 2025 16:17
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Oct 21, 2025

Open in StackBlitz

yarn add https://pkg.pr.new/prettier/prettier/@prettier/[email protected]
yarn add https://pkg.pr.new/prettier/prettier/@prettier/[email protected]
yarn add https://pkg.pr.new/prettier/[email protected]

commit: 1c972e2

@netlify
Copy link
Copy Markdown

netlify bot commented Oct 21, 2025

Deploy Preview for prettier ready!

Name Link
🔨 Latest commit 1c972e2
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/68f8e542e514d00008acc831
😎 Deploy Preview https://deploy-preview-14111--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@fisker fisker marked this pull request as draft October 21, 2025 16:20
@fisker fisker changed the title Refactor TSInterfaceBody print Refactor interface body and object type print Oct 22, 2025
@fisker fisker marked this pull request as ready for review October 22, 2025 14:23
@fisker fisker merged commit 445074d into prettier:main Oct 22, 2025
34 of 35 checks passed
@fisker fisker deleted the ts-interface-body branch October 22, 2025 14:38
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.

Call signatures in interfaces get broken with no-semi

3 participants