Skip to content

Commit

Permalink
fix: Correctly generate TSMappedType (#16394)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Apr 1, 2024
1 parent 48a3e19 commit 22725e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/babel-generator/src/generators/typescript.ts
Expand Up @@ -414,7 +414,7 @@ export function TSIndexedAccessType(
}

export function TSMappedType(this: Printer, node: t.TSMappedType) {
const { nameType, optional, readonly, typeParameter } = node;
const { nameType, optional, readonly, typeParameter, typeAnnotation } = node;
this.token("{");
this.space();
if (readonly) {
Expand Down Expand Up @@ -443,13 +443,15 @@ export function TSMappedType(this: Printer, node: t.TSMappedType) {

this.token("]");

if (optional) {
tokenIfPlusMinus(this, optional);
this.token("?");
if (typeAnnotation) {
if (optional) {
tokenIfPlusMinus(this, optional);
this.token("?");
}
this.token(":");
this.space();
this.print(typeAnnotation, node);
}
this.token(":");
this.space();
this.print(node.typeAnnotation, node);
this.space();
this.token("}");
}
Expand Down
@@ -0,0 +1 @@
type Bar = { [key in Foo] };
@@ -0,0 +1 @@
type Bar = { [key in Foo] };

0 comments on commit 22725e9

Please sign in to comment.