Skip to content

Commit 554bd24

Browse files
authored
Fix checker handling for empty type argument lists (microsoft#34790)
1 parent ff590b6 commit 554bd24

12 files changed

+80
-22
lines changed

src/compiler/checker.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23435,7 +23435,7 @@ namespace ts {
2343523435
// the declared number of type parameters, the call has an incorrect arity.
2343623436
const numTypeParameters = length(signature.typeParameters);
2343723437
const minTypeArgumentCount = getMinTypeArgumentCount(signature.typeParameters);
23438-
return !typeArguments ||
23438+
return !some(typeArguments) ||
2343923439
(typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters);
2344023440
}
2344123441

@@ -24195,7 +24195,7 @@ namespace ts {
2419524195

2419624196
if (isSingleNonGenericCandidate) {
2419724197
const candidate = candidates[0];
24198-
if (typeArguments || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
24198+
if (some(typeArguments) || !hasCorrectArity(node, args, candidate, signatureHelpTrailingComma)) {
2419924199
return undefined;
2420024200
}
2420124201
if (getSignatureApplicabilityError(node, args, candidate, relation, CheckMode.Normal, /*reportErrors*/ false, /*containingMessageChain*/ undefined)) {
@@ -24216,7 +24216,7 @@ namespace ts {
2421624216

2421724217
if (candidate.typeParameters) {
2421824218
let typeArgumentTypes: Type[] | undefined;
24219-
if (typeArguments) {
24219+
if (some(typeArguments)) {
2422024220
typeArgumentTypes = checkTypeArguments(candidate, typeArguments, /*reportErrors*/ false);
2422124221
if (!typeArgumentTypes) {
2422224222
candidateForTypeArgumentError = candidate;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty.
2-
tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 type arguments, but got 0.
2+
tests/cases/compiler/emptyTypeArgumentList.ts(6,9): error TS1099: Type argument list cannot be empty.
33

44

55
==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ====
66
function foo<T>() { }
77
foo<>();
88
~~
99
!!! error TS1099: Type argument list cannot be empty.
10-
11-
!!! error TS2558: Expected 1 type arguments, but got 0.
10+
11+
// https://github.com/microsoft/TypeScript/issues/33041
12+
function noParams() {}
13+
noParams<>();
14+
~~
15+
!!! error TS1099: Type argument list cannot be empty.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
//// [emptyTypeArgumentList.ts]
22
function foo<T>() { }
3-
foo<>();
3+
foo<>();
4+
5+
// https://github.com/microsoft/TypeScript/issues/33041
6+
function noParams() {}
7+
noParams<>();
48

59
//// [emptyTypeArgumentList.js]
610
function foo() { }
711
foo();
12+
// https://github.com/microsoft/TypeScript/issues/33041
13+
function noParams() { }
14+
noParams();

tests/baselines/reference/emptyTypeArgumentList.symbols

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ function foo<T>() { }
66
foo<>();
77
>foo : Symbol(foo, Decl(emptyTypeArgumentList.ts, 0, 0))
88

9+
// https://github.com/microsoft/TypeScript/issues/33041
10+
function noParams() {}
11+
>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8))
12+
13+
noParams<>();
14+
>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8))
15+

tests/baselines/reference/emptyTypeArgumentList.types

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ function foo<T>() { }
33
>foo : <T>() => void
44

55
foo<>();
6-
>foo<>() : any
6+
>foo<>() : void
77
>foo : <T>() => void
88

9+
// https://github.com/microsoft/TypeScript/issues/33041
10+
function noParams() {}
11+
>noParams : () => void
12+
13+
noParams<>();
14+
>noParams<>() : void
15+
>noParams : () => void
16+
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty.
2-
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expected 1 type arguments, but got 0.
2+
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(6,13): error TS1099: Type argument list cannot be empty.
33

44

55
==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ====
66
class foo<T> { }
77
new foo<>();
88
~~
99
!!! error TS1099: Type argument list cannot be empty.
10-
11-
!!! error TS2558: Expected 1 type arguments, but got 0.
10+
11+
// https://github.com/microsoft/TypeScript/issues/33041
12+
class noParams {}
13+
new noParams<>();
14+
~~
15+
!!! error TS1099: Type argument list cannot be empty.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
//// [emptyTypeArgumentListWithNew.ts]
22
class foo<T> { }
3-
new foo<>();
3+
new foo<>();
4+
5+
// https://github.com/microsoft/TypeScript/issues/33041
6+
class noParams {}
7+
new noParams<>();
48

59
//// [emptyTypeArgumentListWithNew.js]
610
var foo = /** @class */ (function () {
@@ -9,3 +13,10 @@ var foo = /** @class */ (function () {
913
return foo;
1014
}());
1115
new foo();
16+
// https://github.com/microsoft/TypeScript/issues/33041
17+
var noParams = /** @class */ (function () {
18+
function noParams() {
19+
}
20+
return noParams;
21+
}());
22+
new noParams();

tests/baselines/reference/emptyTypeArgumentListWithNew.symbols

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ class foo<T> { }
66
new foo<>();
77
>foo : Symbol(foo, Decl(emptyTypeArgumentListWithNew.ts, 0, 0))
88

9+
// https://github.com/microsoft/TypeScript/issues/33041
10+
class noParams {}
11+
>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12))
12+
13+
new noParams<>();
14+
>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12))
15+

tests/baselines/reference/emptyTypeArgumentListWithNew.types

+9-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ class foo<T> { }
33
>foo : foo<T>
44

55
new foo<>();
6-
>new foo<>() : any
6+
>new foo<>() : foo<unknown>
77
>foo : typeof foo
88

9+
// https://github.com/microsoft/TypeScript/issues/33041
10+
class noParams {}
11+
>noParams : noParams
12+
13+
new noParams<>();
14+
>new noParams<>() : noParams
15+
>noParams : typeof noParams
16+

tests/baselines/reference/tsxTypeArgumentResolution.errors.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ tests/cases/conformance/jsx/file.tsx(18,26): error TS2322: Type 'number' is not
33
tests/cases/conformance/jsx/file.tsx(20,13): error TS2558: Expected 1 type arguments, but got 2.
44
tests/cases/conformance/jsx/file.tsx(22,13): error TS2558: Expected 1 type arguments, but got 2.
55
tests/cases/conformance/jsx/file.tsx(24,12): error TS1099: Type argument list cannot be empty.
6-
tests/cases/conformance/jsx/file.tsx(24,13): error TS2558: Expected 1 type arguments, but got 0.
76
tests/cases/conformance/jsx/file.tsx(26,12): error TS1099: Type argument list cannot be empty.
8-
tests/cases/conformance/jsx/file.tsx(26,13): error TS2558: Expected 1 type arguments, but got 0.
97
tests/cases/conformance/jsx/file.tsx(39,14): error TS2344: Type 'Prop' does not satisfy the constraint '{ a: string; }'.
108
Types of property 'a' are incompatible.
119
Type 'number' is not assignable to type 'string'.
@@ -16,7 +14,7 @@ tests/cases/conformance/jsx/file.tsx(51,47): error TS2322: Type 'string' is not
1614
tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not assignable to type 'number'.
1715

1816

19-
==== tests/cases/conformance/jsx/file.tsx (14 errors) ====
17+
==== tests/cases/conformance/jsx/file.tsx (12 errors) ====
2018
import React = require('react');
2119

2220
interface Prop {
@@ -53,14 +51,10 @@ tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not
5351
x = <MyComp<> a={10} b="hi" />; // error
5452
~~
5553
!!! error TS1099: Type argument list cannot be empty.
56-
57-
!!! error TS2558: Expected 1 type arguments, but got 0.
5854

5955
x = <MyComp<> a={10} b="hi"></MyComp>; // error
6056
~~
6157
!!! error TS1099: Type argument list cannot be empty.
62-
63-
!!! error TS2558: Expected 1 type arguments, but got 0.
6458

6559
x= <MyComp<{}> /> // OK
6660

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
function foo<T>() { }
2-
foo<>();
2+
foo<>();
3+
4+
// https://github.com/microsoft/TypeScript/issues/33041
5+
function noParams() {}
6+
noParams<>();
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
class foo<T> { }
2-
new foo<>();
2+
new foo<>();
3+
4+
// https://github.com/microsoft/TypeScript/issues/33041
5+
class noParams {}
6+
new noParams<>();

0 commit comments

Comments
 (0)