Skip to content

Object destructuring in parameters with type and comments results in non-stable format loop #15707

@Jamesernator

Description

@Jamesernator

Prettier 3.1.0
Playground link

--parser typescript

Input:

export default class Foo {
  constructor({ 
    foo,
    // bar = "bar",
    // bazz = "bazz",
  }: FooInit) {}
}

Output:

export default class Foo {
  constructor({
    foo,
  } // bar = "bar",
  // bazz = "bazz",
  : FooInit) {}
}

Expected behavior:

I would expect no changes whatsoever to the original input:

export default class Foo {
  constructor({ 
    foo,
    // bar = "bar",
    // bazz = "bazz",
  }: FooInit) {}
}

Notes

This behaviour is actually fairly buggy, not only is the output not desirable, the output isn't stable, feeding the output back into prettier changes it again:

export default class Foo {
  constructor({
    foo, // bar = "bar",
  } // bazz = "bazz",
  : FooInit) {}
}

which feeding back in becomes (and will from now on alternate between this and the above printing):

export default class Foo {
  constructor({
    foo, // bar = "bar",
    // bazz = "bazz",
  }: FooInit) {}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentsarea:idempotencyIssues with re-printing Prettier’s outputlang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-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