Skip to content

Commit 99a88ac

Browse files
committed
Fix checker handling for empty type argument lists
1 parent cbbbcfa commit 99a88ac

11 files changed

+79
-15
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
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;
Lines changed: 7 additions & 3 deletions
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.
Lines changed: 8 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 9 additions & 1 deletion
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+
Lines changed: 7 additions & 3 deletions
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.
Lines changed: 12 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 9 additions & 1 deletion
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+
Lines changed: 5 additions & 1 deletion
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<>();
Lines changed: 5 additions & 1 deletion
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)