Skip to content

Commit

Permalink
fix: Correctly prints { [key in Bar]? } (#16402)
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
liuxingbaoyu committed Apr 2, 2024
1 parent dd699a8 commit 38c14c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/babel-generator/src/generators/typescript.ts
Expand Up @@ -443,11 +443,12 @@ 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);
Expand Down
@@ -1 +1,4 @@
type Bar = { [key in Foo] };
type Foo2 = { [key in Bar]? };
type Foo3 = { [key in keyof Bar]-? };
type Foo4 = { [key in keyof Bar]+? };
@@ -1 +1,4 @@
type Bar = { [key in Foo] };
type Bar = { [key in Foo] };
type Foo2 = { [key in Bar]? };
type Foo3 = { [key in keyof Bar]-? };
type Foo4 = { [key in keyof Bar]+? };

0 comments on commit 38c14c3

Please sign in to comment.