diff --git a/changelog_unreleased/typescript/17538.md b/changelog_unreleased/typescript/17538.md new file mode 100644 index 000000000..f0dd805dd --- /dev/null +++ b/changelog_unreleased/typescript/17538.md @@ -0,0 +1,22 @@ +#### Don't print extra semicolon after `prettier-ignore`d index-signature (#17538 by @sosukesuzuki) + + +```tsx +// Input +type foo = { + // prettier-ignore + [key: string]: bar; +}; + +// Prettier stable +type foo = { + // prettier-ignore + [key: string]: bar;; +}; + +// Prettier main +type foo = { + // prettier-ignore + [key: string]: bar; +}; +``` diff --git a/src/language-js/print/object.js b/src/language-js/print/object.js index d1d788fb4..32fcd58a8 100644 --- a/src/language-js/print/object.js +++ b/src/language-js/print/object.js @@ -159,7 +159,8 @@ function printObject(path, options, print) { ((lastElem.type === "TSPropertySignature" || lastElem.type === "TSCallSignatureDeclaration" || lastElem.type === "TSMethodSignature" || - lastElem.type === "TSConstructSignatureDeclaration") && + lastElem.type === "TSConstructSignatureDeclaration" || + lastElem.type === "TSIndexSignature") && hasComment(lastElem, CommentCheckFlags.PrettierIgnore)))) ); diff --git a/tests/format/typescript/prettier-ignore/__snapshots__/format.test.js.snap b/tests/format/typescript/prettier-ignore/__snapshots__/format.test.js.snap index 574b60950..367e8cf4f 100644 --- a/tests/format/typescript/prettier-ignore/__snapshots__/format.test.js.snap +++ b/tests/format/typescript/prettier-ignore/__snapshots__/format.test.js.snap @@ -18,6 +18,26 @@ export const foo = // prettier-ignore ================================================================================ `; +exports[`issue-16927.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type Foo = { + // prettier-ignore + [key: string]: bar; +}; + +=====================================output===================================== +type Foo = { + // prettier-ignore + [key: string]: bar; +}; + +================================================================================ +`; + exports[`mapped-types.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/prettier-ignore/issue-16927.ts b/tests/format/typescript/prettier-ignore/issue-16927.ts new file mode 100644 index 000000000..1ec77ded6 --- /dev/null +++ b/tests/format/typescript/prettier-ignore/issue-16927.ts @@ -0,0 +1,4 @@ +type Foo = { + // prettier-ignore + [key: string]: bar; +};