Skip to content

Every run, comments get duplicated. #18389

@paleite

Description

@paleite

Prettier 3.7.3
Playground link

--parser typescript

Input:

// Works - Parenthesis are removed
type Foo = {
  bar:
    | /**
     * cantileveredKangarooTransformer
     */
    (a | b | c);
};

// Works - Parenthesis are kept
type Foo = {
  bar:
    | /**
     * octahedralRhinocerosTransformer
     */
    a
    | (b | c);
};

// Fails - Comment is repeated
type Foo = {
  bar:
    | /**
     * hippopotamicKangarooMutator
     */
    (a | b)
    | c;
};

Output:

// Works - Parenthesis are removed
type Foo = {
  bar: /**
     * cantileveredKangarooTransformer
     */
    a | b | c;
};

// Works - Parenthesis are kept
type Foo = {
  bar:
    | /**
     * octahedralRhinocerosTransformer
     */
    a
    | (b | c);
};

// Fails - Comment is repeated
type Foo = {
  bar:
    | /**
     * hippopotamicKangarooMutator
     */
    (/**
       * hippopotamicKangarooMutator
       */
      a | b)
    | c;
};

Expected output:

// Works - Parenthesis are removed
type Foo = {
  bar: /**
   * cantileveredKangarooTransformer
   */
  a | b | c;
};

// Works - Parenthesis are kept
type Foo = {
  bar:
    | /**
     * octahedralRhinocerosTransformer
     */
    a
    | (b | c);
};

// Fails - Comment is repeated
type Foo = {
  bar:
    | /**
     * hippopotamicKangarooMutator
     */
    (a | b)
    | c;
};

Why?

The comment is repeated, causing it to duplicate the comment on each run.

Metadata

Metadata

Assignees

Labels

area:commentsIssues with how Prettier prints commentsarea:union typeslocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions