-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Inline block comment in mapped type incorrectly moved to separate line #18730
Copy link
Copy link
Closed
Copy link
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)
Description
Prettier 3.8.1
Playground link
--parser typescriptInput:
This is a Prettier test
prettier/tests/format/typescript/comments/mapped_types.ts
Lines 6 to 8 in 812a4d0
| 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:
TSTypeLiteralwith 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)