diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 69a8c4272608c..07deca3caad1d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33604,6 +33604,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkExpressionWithTypeArguments(node: ExpressionWithTypeArguments | TypeQueryNode) { checkGrammarExpressionWithTypeArguments(node); + forEach(node.typeArguments, checkSourceElement); const exprType = node.kind === SyntaxKind.ExpressionWithTypeArguments ? checkExpression(node.expression) : isThisIdentifier(node.exprName) ? checkThisExpression(node.exprName) : checkExpression(node.exprName); diff --git a/tests/baselines/reference/expressionWithJSDocTypeArguments.errors.txt b/tests/baselines/reference/expressionWithJSDocTypeArguments.errors.txt new file mode 100644 index 0000000000000..6ed72dd8b3e2e --- /dev/null +++ b/tests/baselines/reference/expressionWithJSDocTypeArguments.errors.txt @@ -0,0 +1,91 @@ +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(9,21): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(10,20): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(11,21): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,23): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(12,24): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(14,28): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(15,27): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(16,28): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,30): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(17,31): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(19,21): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(20,20): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(21,21): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,23): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(22,24): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(24,28): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(25,27): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(26,28): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,30): error TS8020: JSDoc types can only be used inside documentation comments. +tests/cases/compiler/expressionWithJSDocTypeArguments.ts(27,31): error TS8020: JSDoc types can only be used inside documentation comments. + + +==== tests/cases/compiler/expressionWithJSDocTypeArguments.ts (20 errors) ==== + // Repro from #51802 + + function foo(x: T): T { return x } + + class Bar { constructor(public x: T) { } } + + // Errors expected on all of the following + + const WhatFoo = foo; + ~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const HuhFoo = foo; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const NopeFoo = foo; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const ComeOnFoo = foo; + ~~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + + type TWhatFoo = typeof foo; + ~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type THuhFoo = typeof foo; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type TNopeFoo = typeof foo; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type TComeOnFoo = typeof foo; + ~~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + + const WhatBar = Bar; + ~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const HuhBar = Bar; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const NopeBar = Bar; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + const ComeOnBar = Bar; + ~~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + + type TWhatBar = typeof Bar; + ~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type THuhBar = typeof Bar; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type TNopeBar = typeof Bar; + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + type TComeOnBar = typeof Bar; + ~~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + ~~~~~~~ +!!! error TS8020: JSDoc types can only be used inside documentation comments. + \ No newline at end of file diff --git a/tests/baselines/reference/expressionWithJSDocTypeArguments.js b/tests/baselines/reference/expressionWithJSDocTypeArguments.js new file mode 100644 index 0000000000000..385696f67d5cf --- /dev/null +++ b/tests/baselines/reference/expressionWithJSDocTypeArguments.js @@ -0,0 +1,49 @@ +//// [expressionWithJSDocTypeArguments.ts] +// Repro from #51802 + +function foo(x: T): T { return x } + +class Bar { constructor(public x: T) { } } + +// Errors expected on all of the following + +const WhatFoo = foo; +const HuhFoo = foo; +const NopeFoo = foo; +const ComeOnFoo = foo; + +type TWhatFoo = typeof foo; +type THuhFoo = typeof foo; +type TNopeFoo = typeof foo; +type TComeOnFoo = typeof foo; + +const WhatBar = Bar; +const HuhBar = Bar; +const NopeBar = Bar; +const ComeOnBar = Bar; + +type TWhatBar = typeof Bar; +type THuhBar = typeof Bar; +type TNopeBar = typeof Bar; +type TComeOnBar = typeof Bar; + + +//// [expressionWithJSDocTypeArguments.js] +"use strict"; +// Repro from #51802 +function foo(x) { return x; } +var Bar = /** @class */ (function () { + function Bar(x) { + this.x = x; + } + return Bar; +}()); +// Errors expected on all of the following +var WhatFoo = foo; +var HuhFoo = foo; +var NopeFoo = foo; +var ComeOnFoo = foo; +var WhatBar = Bar; +var HuhBar = Bar; +var NopeBar = Bar; +var ComeOnBar = Bar; diff --git a/tests/baselines/reference/expressionWithJSDocTypeArguments.symbols b/tests/baselines/reference/expressionWithJSDocTypeArguments.symbols new file mode 100644 index 0000000000000..f19930cbf8c69 --- /dev/null +++ b/tests/baselines/reference/expressionWithJSDocTypeArguments.symbols @@ -0,0 +1,83 @@ +=== tests/cases/compiler/expressionWithJSDocTypeArguments.ts === +// Repro from #51802 + +function foo(x: T): T { return x } +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) +>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13)) +>x : Symbol(x, Decl(expressionWithJSDocTypeArguments.ts, 2, 16)) +>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13)) +>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 2, 13)) +>x : Symbol(x, Decl(expressionWithJSDocTypeArguments.ts, 2, 16)) + +class Bar { constructor(public x: T) { } } +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) +>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 4, 10)) +>x : Symbol(Bar.x, Decl(expressionWithJSDocTypeArguments.ts, 4, 27)) +>T : Symbol(T, Decl(expressionWithJSDocTypeArguments.ts, 4, 10)) + +// Errors expected on all of the following + +const WhatFoo = foo; +>WhatFoo : Symbol(WhatFoo, Decl(expressionWithJSDocTypeArguments.ts, 8, 5)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +const HuhFoo = foo; +>HuhFoo : Symbol(HuhFoo, Decl(expressionWithJSDocTypeArguments.ts, 9, 5)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +const NopeFoo = foo; +>NopeFoo : Symbol(NopeFoo, Decl(expressionWithJSDocTypeArguments.ts, 10, 5)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +const ComeOnFoo = foo; +>ComeOnFoo : Symbol(ComeOnFoo, Decl(expressionWithJSDocTypeArguments.ts, 11, 5)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +type TWhatFoo = typeof foo; +>TWhatFoo : Symbol(TWhatFoo, Decl(expressionWithJSDocTypeArguments.ts, 11, 32)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +type THuhFoo = typeof foo; +>THuhFoo : Symbol(THuhFoo, Decl(expressionWithJSDocTypeArguments.ts, 13, 30)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +type TNopeFoo = typeof foo; +>TNopeFoo : Symbol(TNopeFoo, Decl(expressionWithJSDocTypeArguments.ts, 14, 35)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +type TComeOnFoo = typeof foo; +>TComeOnFoo : Symbol(TComeOnFoo, Decl(expressionWithJSDocTypeArguments.ts, 15, 36)) +>foo : Symbol(foo, Decl(expressionWithJSDocTypeArguments.ts, 0, 0)) + +const WhatBar = Bar; +>WhatBar : Symbol(WhatBar, Decl(expressionWithJSDocTypeArguments.ts, 18, 5)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +const HuhBar = Bar; +>HuhBar : Symbol(HuhBar, Decl(expressionWithJSDocTypeArguments.ts, 19, 5)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +const NopeBar = Bar; +>NopeBar : Symbol(NopeBar, Decl(expressionWithJSDocTypeArguments.ts, 20, 5)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +const ComeOnBar = Bar; +>ComeOnBar : Symbol(ComeOnBar, Decl(expressionWithJSDocTypeArguments.ts, 21, 5)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +type TWhatBar = typeof Bar; +>TWhatBar : Symbol(TWhatBar, Decl(expressionWithJSDocTypeArguments.ts, 21, 32)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +type THuhBar = typeof Bar; +>THuhBar : Symbol(THuhBar, Decl(expressionWithJSDocTypeArguments.ts, 23, 30)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +type TNopeBar = typeof Bar; +>TNopeBar : Symbol(TNopeBar, Decl(expressionWithJSDocTypeArguments.ts, 24, 35)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + +type TComeOnBar = typeof Bar; +>TComeOnBar : Symbol(TComeOnBar, Decl(expressionWithJSDocTypeArguments.ts, 25, 36)) +>Bar : Symbol(Bar, Decl(expressionWithJSDocTypeArguments.ts, 2, 37)) + diff --git a/tests/baselines/reference/expressionWithJSDocTypeArguments.types b/tests/baselines/reference/expressionWithJSDocTypeArguments.types new file mode 100644 index 0000000000000..b3b1cdf96c667 --- /dev/null +++ b/tests/baselines/reference/expressionWithJSDocTypeArguments.types @@ -0,0 +1,86 @@ +=== tests/cases/compiler/expressionWithJSDocTypeArguments.ts === +// Repro from #51802 + +function foo(x: T): T { return x } +>foo : (x: T) => T +>x : T +>x : T + +class Bar { constructor(public x: T) { } } +>Bar : Bar +>x : T + +// Errors expected on all of the following + +const WhatFoo = foo; +>WhatFoo : (x: any) => any +>foo : (x: any) => any +>foo : (x: T) => T + +const HuhFoo = foo; +>HuhFoo : (x: string | null) => string | null +>foo : (x: string | null) => string | null +>foo : (x: T) => T + +const NopeFoo = foo; +>NopeFoo : (x: string | null) => string | null +>foo : (x: string | null) => string | null +>foo : (x: T) => T + +const ComeOnFoo = foo; +>ComeOnFoo : (x: string | null) => string | null +>foo : (x: string | null) => string | null +>foo : (x: T) => T + +type TWhatFoo = typeof foo; +>TWhatFoo : (x: any) => any +>foo : (x: T) => T + +type THuhFoo = typeof foo; +>THuhFoo : (x: string | null) => string | null +>foo : (x: T) => T + +type TNopeFoo = typeof foo; +>TNopeFoo : (x: string | null) => string | null +>foo : (x: T) => T + +type TComeOnFoo = typeof foo; +>TComeOnFoo : (x: string | null) => string | null +>foo : (x: T) => T + +const WhatBar = Bar; +>WhatBar : { new (x: any): Bar; prototype: Bar; } +>Bar : { new (x: any): Bar; prototype: Bar; } +>Bar : typeof Bar + +const HuhBar = Bar; +>HuhBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + +const NopeBar = Bar; +>NopeBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + +const ComeOnBar = Bar; +>ComeOnBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + +type TWhatBar = typeof Bar; +>TWhatBar : { new (x: any): Bar; prototype: Bar; } +>Bar : typeof Bar + +type THuhBar = typeof Bar; +>THuhBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + +type TNopeBar = typeof Bar; +>TNopeBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + +type TComeOnBar = typeof Bar; +>TComeOnBar : { new (x: string | null): Bar; prototype: Bar; } +>Bar : typeof Bar + diff --git a/tests/baselines/reference/importWithTypeArguments.errors.txt b/tests/baselines/reference/importWithTypeArguments.errors.txt index 2981a63bec737..2afa34c53afec 100644 --- a/tests/baselines/reference/importWithTypeArguments.errors.txt +++ b/tests/baselines/reference/importWithTypeArguments.errors.txt @@ -1,11 +1,14 @@ tests/cases/conformance/types/import/importWithTypeArguments.ts(1,1): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. +tests/cases/conformance/types/import/importWithTypeArguments.ts(1,8): error TS2304: Cannot find name 'T'. tests/cases/conformance/types/import/importWithTypeArguments.ts(2,11): error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. -==== tests/cases/conformance/types/import/importWithTypeArguments.ts (2 errors) ==== +==== tests/cases/conformance/types/import/importWithTypeArguments.ts (3 errors) ==== import ~~~~~~~~~ !!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. + ~ +!!! error TS2304: Cannot find name 'T'. const a = import ~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1326: This use of 'import' is invalid. 'import()' calls can be written, but they must have parentheses and cannot have type arguments. diff --git a/tests/baselines/reference/parserMemberAccessExpression1.errors.txt b/tests/baselines/reference/parserMemberAccessExpression1.errors.txt index a427715dbd793..4a68a15ac3a7c 100644 --- a/tests/baselines/reference/parserMemberAccessExpression1.errors.txt +++ b/tests/baselines/reference/parserMemberAccessExpression1.errors.txt @@ -4,12 +4,14 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(2,9): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,1): error TS2304: Cannot find name 'Foo'. tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,4): error TS1477: An instantiation expression cannot be followed by a property access. +tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(3,5): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,1): error TS2304: Cannot find name 'Foo'. tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,4): error TS1477: An instantiation expression cannot be followed by a property access. +tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,5): error TS2304: Cannot find name 'T'. tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts(4,12): error TS2304: Cannot find name 'T'. -==== tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts (9 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression1.ts (11 errors) ==== Foo(); ~~~ !!! error TS2304: Cannot find name 'Foo'. @@ -25,11 +27,15 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserMemberAccessExpression !!! error TS2304: Cannot find name 'Foo'. ~~~ !!! error TS1477: An instantiation expression cannot be followed by a property access. + ~ +!!! error TS2304: Cannot find name 'T'. Foo.Bar(); ~~~ !!! error TS2304: Cannot find name 'Foo'. ~~~ !!! error TS1477: An instantiation expression cannot be followed by a property access. + ~ +!!! error TS2304: Cannot find name 'T'. ~ !!! error TS2304: Cannot find name 'T'. \ No newline at end of file diff --git a/tests/baselines/reference/parserTypeQuery8.errors.txt b/tests/baselines/reference/parserTypeQuery8.errors.txt index ab24604ba90fa..88f798c5168c5 100644 --- a/tests/baselines/reference/parserTypeQuery8.errors.txt +++ b/tests/baselines/reference/parserTypeQuery8.errors.txt @@ -1,7 +1,10 @@ tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts(1,15): error TS2304: Cannot find name 'A'. +tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts(1,17): error TS2304: Cannot find name 'B'. -==== tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/Types/parserTypeQuery8.ts (2 errors) ==== var v: typeof A ~ -!!! error TS2304: Cannot find name 'A'. \ No newline at end of file +!!! error TS2304: Cannot find name 'A'. + ~ +!!! error TS2304: Cannot find name 'B'. \ No newline at end of file diff --git a/tests/cases/compiler/expressionWithJSDocTypeArguments.ts b/tests/cases/compiler/expressionWithJSDocTypeArguments.ts new file mode 100644 index 0000000000000..097faf8b1a6f2 --- /dev/null +++ b/tests/cases/compiler/expressionWithJSDocTypeArguments.ts @@ -0,0 +1,29 @@ +// @strict: true + +// Repro from #51802 + +function foo(x: T): T { return x } + +class Bar { constructor(public x: T) { } } + +// Errors expected on all of the following + +const WhatFoo = foo; +const HuhFoo = foo; +const NopeFoo = foo; +const ComeOnFoo = foo; + +type TWhatFoo = typeof foo; +type THuhFoo = typeof foo; +type TNopeFoo = typeof foo; +type TComeOnFoo = typeof foo; + +const WhatBar = Bar; +const HuhBar = Bar; +const NopeBar = Bar; +const ComeOnBar = Bar; + +type TWhatBar = typeof Bar; +type THuhBar = typeof Bar; +type TNopeBar = typeof Bar; +type TComeOnBar = typeof Bar;