diff --git a/changelog_unreleased/typescript/pr-7729.md b/changelog_unreleased/typescript/pr-7729.md
new file mode 100644
index 000000000..6a5f7f97d
--- /dev/null
+++ b/changelog_unreleased/typescript/pr-7729.md
@@ -0,0 +1,13 @@
+#### Fix printing of comments in empty type parameters ([#7729](https://github.com/prettier/prettier/pull/7729) by [@sosukesuzuki](https://github.com/sosukesuzuki))
+
+
+```ts
+// Input
+const a: T* comment */> = 1;
+
+// Prettier stable
+Error: Comment "comment" was not printed. Please report this error!
+
+// Prettier master
+const a: T* comment */> = 1;
+```
diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js
index 8ee3608f1..9fefddb39 100644
--- a/src/language-js/printer-estree.js
+++ b/src/language-js/printer-estree.js
@@ -4638,8 +4638,31 @@ function printTypeParameters(path, options, print, paramsKey) {
n[paramsKey][0].type !== "TSIndexedAccessType" &&
n[paramsKey][0].type !== "TSArrayType")));
+ function printDanglingCommentsForInline(n) {
+ if (!hasDanglingComments(n)) {
+ return "";
+ }
+ const hasOnlyBlockComments = n.comments.every(
+ handleComments.isBlockComment
+ );
+ const printed = comments.printDanglingComments(
+ path,
+ options,
+ /* sameIndent */ hasOnlyBlockComments
+ );
+ if (hasOnlyBlockComments) {
+ return printed;
+ }
+ return concat([printed, hardline]);
+ }
+
if (shouldInline) {
- return concat(["<", join(", ", path.map(print, paramsKey)), ">"]);
+ return concat([
+ "<",
+ join(", ", path.map(print, paramsKey)),
+ printDanglingCommentsForInline(n),
+ ">"
+ ]);
}
return group(
diff --git a/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap
index d0a344660..1282449f9 100644
--- a/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap
@@ -663,9 +663,69 @@ printWidth: 80
| printWidth
=====================================input======================================
functionName();
+const a: T* comment */> = 1;
+functionName* comment */>();
+function foo* comment */>() {}
+interface Foo {
+ * comment */>(arg): any;
+}
+type T = * comment */>(arg) => any;
+
+functionName<
+ A // comment
+>();
+const a: T<
+ // comment
+> = 1;
+functionName<
+ // comment
+>();
+function foo<
+ // comment
+>() {}
+interface Foo {
+ <
+ A// comment
+ >(arg): any;
+}
+type T = <
+ // comment
+>(arg) => any;
=====================================output=====================================
functionName();
+const a: T* comment */> = 1;
+functionName* comment */>();
+function foo* comment */>() {}
+interface Foo {
+ * comment */>(arg): any;
+}
+type T = * comment */>(arg) => any;
+
+functionName<
+ A // comment
+>();
+const a: T<
+ // comment
+> = 1;
+functionName<
+ // comment
+>();
+function foo<
+ // comment
+>() {}
+interface Foo {
+ <
+ A // comment
+ >(
+ arg
+ ): any;
+}
+type T = <
+ // comment
+>(
+ arg
+) => any;
================================================================================
`;
diff --git a/tests/typescript_comments/type-parameters.ts b/tests/typescript_comments/type-parameters.ts
index e993143af..42990a4ea 100644
--- a/tests/typescript_comments/type-parameters.ts
+++ b/tests/typescript_comments/type-parameters.ts
@@ -1 +1,29 @@
functionName();
+const a: T* comment */> = 1;
+functionName* comment */>();
+function foo* comment */>() {}
+interface Foo {
+ * comment */>(arg): any;
+}
+type T = * comment */>(arg) => any;
+
+functionName<
+ A // comment
+>();
+const a: T<
+ // comment
+> = 1;
+functionName<
+ // comment
+>();
+function foo<
+ // comment
+>() {}
+interface Foo {
+ <
+ A// comment
+ >(arg): any;
+}
+type T = <
+ // comment
+>(arg) => any;