Skip to content

Inline block comment in mapped type incorrectly moved to separate line #18730

@Dunqing

Description

@Dunqing

Prettier 3.8.1
Playground link

--parser typescript

Input:

This is a Prettier test

type B = {
/* commentB */ [b in B]: string
}

type B = {
  /* commentB */ [b in B]: string
}

type TSTypeLiteral = {
  /* literal */ b: string;
}

Output:

type B = {
  /* commentB */
  [b in B]: string;
};

type TSTypeLiteral = {
  /* literal */ b: string;
};

Expected output:

type B = {
  /* commentB */ [b in B]: string;
};

type TSTypeLiteral = {
  /* literal */ b: string;
};

Why?

Prettier handles inline block comments inconsistently between mapped types and regular type literal properties:

  • TSTypeLiteral with property signature: comment stays inline ✓
  • TSMappedType: comment is moved to a separate line ✗

Both cases have the same structure—a block comment preceding a type member—so they should be formatted consistently. The comment in the mapped type should remain on the same line as the member it annotates.

Metadata

Metadata

Assignees

Labels

lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions