Prettier 3.8.1
Playground link
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.
Prettier 3.8.1
Playground link
Input:
This is a Prettier test
prettier/tests/format/typescript/comments/mapped_types.ts
Lines 6 to 8 in 812a4d0
Output:
Expected output:
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.