diff --git a/tsc/internal/fourslash/tests/hoverMappedTypePropertyJSDoc_test.go b/tsc/internal/fourslash/tests/hoverMappedTypePropertyJSDoc_test.go index 37398b3e11b75..1b79314469901 100644 --- a/tsc/internal/fourslash/tests/hoverMappedTypePropertyJSDoc_test.go +++ b/tsc/internal/fourslash/tests/hoverMappedTypePropertyJSDoc_test.go @@ -35,3 +35,14 @@ A.X/*2*/; defer done() f.VerifyBaselineHover(t) } + +func TestHoverMappedTypeWithoutPropertyType(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = ` +declare function uhoh/*1*/(x: { [K in keyof T] }): void; +` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineHover(t) +} diff --git a/tsc/internal/printer/printer.go b/tsc/internal/printer/printer.go index ae279d9666341..ac8f4353dc668 100644 --- a/tsc/internal/printer/printer.go +++ b/tsc/internal/printer/printer.go @@ -2181,9 +2181,11 @@ func (p *Printer) emitMappedType(node *ast.MappedTypeNode) { p.writePunctuation("?") } } - p.writePunctuation(":") - p.writeSpace() - p.emitTypeNodeOutsideExtends(node.Type) + if node.Type != nil { + p.writePunctuation(":") + p.writeSpace() + p.emitTypeNodeOutsideExtends(node.Type) + } p.writeTrailingSemicolon() if node.Members != nil { if len(node.Members.Nodes) > 0 { diff --git a/tsc/testdata/baselines/reference/fourslash/quickInfo/hoverMappedTypeWithoutPropertyType.baseline b/tsc/testdata/baselines/reference/fourslash/quickInfo/hoverMappedTypeWithoutPropertyType.baseline new file mode 100644 index 0000000000000..7941d30d1a03f --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/quickInfo/hoverMappedTypeWithoutPropertyType.baseline @@ -0,0 +1,41 @@ +// === QuickInfo === +=== /hoverMappedTypeWithoutPropertyType.ts === +// +// declare function uhoh(x: { [K in keyof T] }): void; +// ^^^^ +// | ---------------------------------------------------------------------- +// | ```typescript +// | function uhoh(x: { [K in keyof T]; }): void +// | ``` +// | +// | ---------------------------------------------------------------------- +// +[ + { + "marker": { + "Position": 22, + "LSPosition": { + "line": 1, + "character": 21 + }, + "Name": "1", + "Data": {} + }, + "item": { + "contents": { + "kind": "markdown", + "value": "```typescript\nfunction uhoh(x: { [K in keyof T]; }): void\n```\n" + }, + "range": { + "start": { + "line": 1, + "character": 17 + }, + "end": { + "line": 1, + "character": 21 + } + } + } + } +] \ No newline at end of file