Skip to content

Comments in the single item union type are placed incorrectly in the TSTypeAliasDeclaration #18834

@Dunqing

Description

@Dunqing

Prettier 3.8.1
Playground link

--parser babel-ts

Input:
https://github.com/prettier/prettier/blob/812a4d0071270f61a7aa549d625b618be7e09d71/tests/format/typescript/union/single-type/single-type.ts#L1-L7

type A1 =
  /* 1 */ | /* 2 */ (
    /* 3 */ | /* 4 */ {
        key: string;
      }
  );

Output:

type A1 /* 2 */ = /* 1 */ /* 3 */ /* 4 */ {
  key: string;
};

Expected output:

type A1 = /* 1 */ /* 2 */ /* 3 */ /* 4 */ {
  key: string;
};

Why?

Comment /* 2 */ moves from after = to before =. This changes the comment from annotating the type value to annotating the type name. The reordering of comments seems arbitrary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:commentsIssues with how Prettier prints commentslang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions