Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TypeScript: avoid trailing commas on index signatures with only one p…
…arameter (#7836)
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#### Avoid trailing commas on index signatures with only one parameter ([#7836](https://github.com/prettier/prettier/pull/7836) by [@bakkot](https://github.com/bakkot)) | ||
|
||
TypeScript index signatures technically allow multiple parameters and trailing commas, but it's an error to have multiple parameters there, and Babel's TypeScript parser does not accept them. So Prettier now avoids putting a trailing comma there when you have only one parameter. | ||
|
||
<!-- prettier-ignore --> | ||
```ts | ||
// Input | ||
export type A = { | ||
a?: { | ||
[ | ||
x: string | ||
]: typeof SomeLongLongLongTypeName[keyof typeof SomeLongLongLongTypeName]; | ||
} | null; | ||
}; | ||
|
||
// Prettier stable | ||
export type A = { | ||
a?: { | ||
[ | ||
x: string, | ||
]: typeof SomeLongLongLongTypeName[keyof typeof SomeLongLongLongTypeName]; | ||
} | null; | ||
}; | ||
|
||
// Prettier master | ||
export type A = { | ||
a?: { | ||
[ | ||
x: string | ||
]: typeof SomeLongLongLongTypeName[keyof typeof SomeLongLongLongTypeName]; | ||
} | null; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters