Visitar URL original
Object destructuring in parameters with type and comments results in non-stable format loop · Issue #15707 · prettier/prettier · GitHub
Skip to content

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

Closed

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) {}
}

Activity

  1. added
    area:commentsIssues with how Prettier prints comments
    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)
    area:idempotencyIssues with re-printing Prettier’s output
    on Nov 23, 2023
  2. locked as resolved and limited conversation to collaborators on Feb 23, 2024
  3. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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