Typescript: Prettier incorrectly breaks up constructor properties from modifiers when there is a decorator and comment before it (original) (raw)
Prettier 3.2.5
Playground link
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