diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 247381f02516b..e57a3fa98f390 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3189,7 +3189,8 @@ namespace ts { const pos = getNodePos(); parseExpected(SyntaxKind.TypeOfKeyword); const entityName = parseEntityName(/*allowReservedWords*/ true, /*allowPrivateIdentifiers*/ true); - const typeArguments = tryParseTypeArguments(); + // Make sure we perform ASI to prevent parsing the next line's type arguments as part of an instantiation expression. + const typeArguments = !scanner.hasPrecedingLineBreak() ? tryParseTypeArguments() : undefined; return finishNode(factory.createTypeQueryNode(entityName, typeArguments), pos); } diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.js b/tests/baselines/reference/newLineInTypeofInstantiation.js new file mode 100644 index 0000000000000..b43b677030531 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.js @@ -0,0 +1,9 @@ +//// [newLineInTypeofInstantiation.ts] +interface Example { + (a: number): typeof a + + (): void +} + + +//// [newLineInTypeofInstantiation.js] diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.symbols b/tests/baselines/reference/newLineInTypeofInstantiation.symbols new file mode 100644 index 0000000000000..2a3ccf8097e86 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/newLineInTypeofInstantiation.ts === +interface Example { +>Example : Symbol(Example, Decl(newLineInTypeofInstantiation.ts, 0, 0)) + + (a: number): typeof a +>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5)) +>a : Symbol(a, Decl(newLineInTypeofInstantiation.ts, 1, 5)) + + (): void +>T : Symbol(T, Decl(newLineInTypeofInstantiation.ts, 3, 5)) +} + diff --git a/tests/baselines/reference/newLineInTypeofInstantiation.types b/tests/baselines/reference/newLineInTypeofInstantiation.types new file mode 100644 index 0000000000000..a57d7df124b95 --- /dev/null +++ b/tests/baselines/reference/newLineInTypeofInstantiation.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/newLineInTypeofInstantiation.ts === +interface Example { + (a: number): typeof a +>a : number +>a : number + + (): void +} + diff --git a/tests/cases/compiler/newLineInTypeofInstantiation.ts b/tests/cases/compiler/newLineInTypeofInstantiation.ts new file mode 100644 index 0000000000000..99259acec79f4 --- /dev/null +++ b/tests/cases/compiler/newLineInTypeofInstantiation.ts @@ -0,0 +1,5 @@ +interface Example { + (a: number): typeof a + + (): void +}