Skip to content

Typescript: Prettier incorrectly breaks up constructor properties from modifiers when there is a decorator and comment before it #16207

@Woodz

Description

@Woodz

Prettier 3.2.5
Playground link

--parser typescript

Input:

function required(target: Object, propertyKey: string | symbol, parameterIndex: number) {
}

class Foo {
  constructor(
    @required
    // prettier-ignore
    protected readonly myParam: string,
  ) {}
}

Output:

function required(
  target: Object,
  propertyKey: string | symbol,
  parameterIndex: number,
) {}

class Foo {
  constructor(
    @required
    protected readonly // prettier-ignore
    myParam: string,
  ) {}
}

Expected output:

function required(
  target: Object,
  propertyKey: string | symbol,
  parameterIndex: number,
) {}

class Foo {
  constructor(
    @required
    // prettier-ignore
    protected readonly myParam: string,
  ) {}
}

Why?

Because protected readonly on a separate line is invalid Typescript syntax, plus the prettier-ignore comment applies to the next line, so by moving it down the scope has changed

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentslang: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