[TypeScript]Keep a trailing comma on tuple types (#6172)
parent
9ee56cdcfd
commit
ed2055b81f
|
@ -433,6 +433,31 @@ f[(a::b)];
|
|||
f[a::b];
|
||||
```
|
||||
|
||||
### TypeScript: Add trailing comma on tuple types when `trailing-commma` options is `all` ([#6172] by [@sosukesuzuki])
|
||||
|
||||
TypeScript supports a trailing comma on tuple types since version 3.3.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
export type Foo = [
|
||||
number,
|
||||
number, // comment
|
||||
];
|
||||
|
||||
// Output (Prettier stable)
|
||||
export type Foo = [
|
||||
number,
|
||||
number // comment
|
||||
];
|
||||
|
||||
// Output (Prettier master);
|
||||
export type Foo = [
|
||||
number,
|
||||
number, // comment
|
||||
];
|
||||
```
|
||||
|
||||
[#5979]: https://github.com/prettier/prettier/pull/5979
|
||||
[#6086]: https://github.com/prettier/prettier/pull/6086
|
||||
[#6088]: https://github.com/prettier/prettier/pull/6088
|
||||
|
@ -454,6 +479,7 @@ f[a::b];
|
|||
[#6146]: https://github.com/prettier/prettier/pull/6146
|
||||
[#6152]: https://github.com/prettier/prettier/pull/6152
|
||||
[#6159]: https://github.com/prettier/prettier/pull/6159
|
||||
[#6172]: https://github.com/prettier/prettier/pull/6172
|
||||
[@belochub]: https://github.com/belochub
|
||||
[@brainkim]: https://github.com/brainkim
|
||||
[@duailibe]: https://github.com/duailibe
|
||||
|
|
|
@ -2487,10 +2487,7 @@ function printPathNoParens(path, options, print, args) {
|
|||
printArrayItems(path, options, typesField, print)
|
||||
])
|
||||
),
|
||||
// TypeScript doesn't support trailing commas in tuple types
|
||||
n.type === "TSTupleType"
|
||||
? ""
|
||||
: ifBreak(shouldPrintComma(options) ? "," : ""),
|
||||
ifBreak(shouldPrintComma(options) ? "," : ""),
|
||||
comments.printDanglingComments(path, options, /* sameIndent */ true),
|
||||
softline,
|
||||
"]"
|
||||
|
|
|
@ -40,6 +40,47 @@ export interface ShopQueryResult {
|
|||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`trailing-comma.ts 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
export interface ShopQueryResult {
|
||||
chic: boolean;
|
||||
location: number[];
|
||||
menus: Menu[];
|
||||
openingDays: number[];
|
||||
closingDays: [
|
||||
{
|
||||
from: string,
|
||||
to: string,
|
||||
}, // <== this one
|
||||
];
|
||||
shop: string;
|
||||
distance: number;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
export interface ShopQueryResult {
|
||||
chic: boolean;
|
||||
location: number[];
|
||||
menus: Menu[];
|
||||
openingDays: number[];
|
||||
closingDays: [
|
||||
{
|
||||
from: string;
|
||||
to: string;
|
||||
}, // <== this one
|
||||
];
|
||||
shop: string;
|
||||
distance: number;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`tuple.ts 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
@ -68,3 +109,33 @@ export type SCMRawResource = [
|
|||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`tuple.ts 2`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
trailingComma: "all"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
export type SCMRawResource = [
|
||||
number /*handle*/,
|
||||
string /*resourceUri*/,
|
||||
modes.Command /*command*/,
|
||||
string[] /*icons: light, dark*/,
|
||||
boolean /*strike through*/,
|
||||
boolean /*faded*/
|
||||
];
|
||||
|
||||
=====================================output=====================================
|
||||
export type SCMRawResource = [
|
||||
number /*handle*/,
|
||||
string /*resourceUri*/,
|
||||
modes.Command /*command*/,
|
||||
string[] /*icons: light, dark*/,
|
||||
boolean /*strike through*/,
|
||||
boolean /*faded*/,
|
||||
];
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
run_spec(__dirname, ["typescript"]);
|
||||
run_spec(__dirname, ["typescript"], { trailingComma: "all" });
|
||||
|
|
Loading…
Reference in New Issue