Skip to content

Conversation

@sosukesuzuki
Copy link
Member

Previously, a trailing comma after single type parameter in arrow function was cleaned up. The formatted result is valid as ts, but is invalid as tsx. This pr is fix to keep a trailing comma for formatting to valid tsx.

Fixes #6114

  • 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 the CHANGELOG.unreleased.md file following the template.
  • I’ve read the contributing guidelines.

Try the playground for this PR

parts.push(" = ", path.call(print, "default"));
}

if (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment here just so our future selves can better understand why this is here?

@duailibe duailibe merged commit e3b2f4a into prettier:master May 13, 2019
@sosukesuzuki sosukesuzuki deleted the 6114-keep-tsx-generics-trailing-comma branch May 13, 2019 18:02
@niieani
Copy link

niieani commented Jun 6, 2019

How can we test this in the playground? I wanted to report the same bug, cause it wasn't working in the playground (or in the VSCode plugin), and then I found this PR, which seems to be fixing this.

@lydell
Copy link
Member

lydell commented Jun 7, 2019

Hmm, I thought this was part of 1.18 but I can't see the comma on the playground either.

Prettier 1.18.0
Playground link

--parser typescript

Input:

  type G<T> = any;
  const myFunc = <T,>(arg1: G<T>) => false;

Output:

type G<T> = any;
const myFunc = <T>(arg1: G<T>) => false;

@duailibe Do you know?

EDIT: Now I get it. The code looks at the file name and checks if it ends with .tsx. I guess that's not the case in the playground. Maybe with should assume that playground code is .tsx code though.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Sep 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 5, 2019
@lipis lipis added this to the 1.19 milestone Sep 11, 2019
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.

Typescript generics, TSX and trailing commas (prettier generates invalid syntax)

5 participants