0

When I am using fluent interfaces in TypeScript I normally want different method calls on different lines while by default prettier tries to format it in one single line (if not too long). A similar behavior for union types. It seems that prettier supports a workaround by adding an empty comment (//), see the examples below. The question: Is this //-workaround an official feature of prettier and if yes then where do I find the documentation for that?

const x = a().b().c();

/* prettier output:
const x = a().b().c();
*/

const y = a()
  .b()
  .c();

/* prettier output:
const y = a().b().c();
*/

const z = a() //
  .b()
  .c();

/* prettier output:
const z = a() //
  .b()
  .c();
*/

type A =
  | "x"
  | "y"
  | "z";

/* prettier output:
type A = "x" | "y" | "z";
*/

type B  =
  | "x" //
  | "y"
  | "z";

/* prettier output:
type B =
  | "x" //
  | "y"
  | "z";
*/

Natasha
  • 516
  • 7
  • 24
  • 1
    How else can Prettier print that comment without splitting the line? – thorn0 Apr 30 '21 at 19:31
  • Thanks thorn0, I think I get it. I just didn't know whether this is an official "feature". But yeah, "splitting the line" may be the only reasonable way for prettier to print that pattern. – Natasha May 01 '21 at 10:58

0 Answers0