Print trailing comma in TSImportType options (#17798)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-09-23 17:51:36 +08:00
1 parent 29622cc4f7
commit b7b2b0d434
6 files changed
+78 -8

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
#### Print trailing comma in `TSImportType` options (#17798 by @fisker)
Trailing comma in import type attribute wasn't allowed before TypeScript v5.9, now [the bug](https://github.com/microsoft/TypeScript/issues/61916) has been fixed.
<!-- prettier-ignore -->
```tsx
// Input
type A = import("foo", {
with:{
type:'json',
} // <- Should be a comma here
})
// Prettier stable
type A = import("foo", {
with: {
type: "json",
} // <- Should be a comma here
});
// Prettier main
type A = import("foo", {
with: {
type: "json",
}, // <- Should be a comma here
});
```
+1 -6
View File
@@ -161,12 +161,7 @@ function printObject(path, options, print) {
lastElem.type === "TSMethodSignature" ||
lastElem.type === "TSConstructSignatureDeclaration" ||
lastElem.type === "TSIndexSignature") &&
hasComment(lastElem, CommentCheckFlags.PrettierIgnore)))) ||
// https://github.com/microsoft/TypeScript/issues/61916
path.match(
undefined,
(node, key) => node.type === "TSImportType" && key === "options",
)
hasComment(lastElem, CommentCheckFlags.PrettierIgnore))))
);
let content;
@@ -0,0 +1,37 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`comma.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
type A = import("foo", {
with: {
type: "json",}})
type A = import("foo", {
with: {
type: "json"},})
// Not supported, https://github.com/microsoft/TypeScript/issues/61489
// type A = import("foo", {
// with: {
// type: "json"}},)
=====================================output=====================================
type A = import("foo", {
with: {
type: "json",
},
});
type A = import("foo", {
with: {
type: "json",
},
});
// Not supported, https://github.com/microsoft/TypeScript/issues/61489
// type A = import("foo", {
// with: {
// type: "json"}},)
================================================================================
`;
@@ -0,0 +1,10 @@
type A = import("foo", {
with: {
type: "json",}})
type A = import("foo", {
with: {
type: "json"},})
// Not supported, https://github.com/microsoft/TypeScript/issues/61489
// type A = import("foo", {
// with: {
// type: "json"}},)
@@ -0,0 +1 @@
runFormatTest(import.meta, ["typescript"]);
@@ -147,13 +147,13 @@ type C = import(
{
with: {
type: "json",
}
},
}
);
type D = import(
"./long/long/long/long/long/long/long/long/long/long/path/to/module",
{
with: { type: "json" }
with: { type: "json" },
}
);