Skip to content

Fix checker handling for empty type argument lists #34790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23435,7 +23435,7 @@ namespace ts {
// the declared number of type parameters, the call has an incorrect arity.
const numTypeParameters = length(signature.typeParameters);
const minTypeArgumentCount = getMinTypeArgumentCount(signature.typeParameters);
return !typeArguments ||
return !some(typeArguments) ||
(typeArguments.length >= minTypeArgumentCount && typeArguments.length <= numTypeParameters);
}

Expand Down Expand Up @@ -24195,7 +24195,7 @@ namespace ts {

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

if (candidate.typeParameters) {
let typeArgumentTypes: Type[] | undefined;
if (typeArguments) {
if (some(typeArguments)) {
typeArgumentTypes = checkTypeArguments(candidate, typeArguments, /*reportErrors*/ false);
if (!typeArgumentTypes) {
candidateForTypeArgumentError = candidate;
Expand Down
10 changes: 7 additions & 3 deletions tests/baselines/reference/emptyTypeArgumentList.errors.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
tests/cases/compiler/emptyTypeArgumentList.ts(2,4): error TS1099: Type argument list cannot be empty.
tests/cases/compiler/emptyTypeArgumentList.ts(2,5): error TS2558: Expected 1 type arguments, but got 0.
tests/cases/compiler/emptyTypeArgumentList.ts(6,9): error TS1099: Type argument list cannot be empty.


==== tests/cases/compiler/emptyTypeArgumentList.ts (2 errors) ====
function foo<T>() { }
foo<>();
~~
!!! error TS1099: Type argument list cannot be empty.

!!! error TS2558: Expected 1 type arguments, but got 0.

// https://github.com/microsoft/TypeScript/issues/33041
function noParams() {}
noParams<>();
~~
!!! error TS1099: Type argument list cannot be empty.
9 changes: 8 additions & 1 deletion tests/baselines/reference/emptyTypeArgumentList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
//// [emptyTypeArgumentList.ts]
function foo<T>() { }
foo<>();
foo<>();

// https://github.com/microsoft/TypeScript/issues/33041
function noParams() {}
noParams<>();

//// [emptyTypeArgumentList.js]
function foo() { }
foo();
// https://github.com/microsoft/TypeScript/issues/33041
function noParams() { }
noParams();
7 changes: 7 additions & 0 deletions tests/baselines/reference/emptyTypeArgumentList.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ function foo<T>() { }
foo<>();
>foo : Symbol(foo, Decl(emptyTypeArgumentList.ts, 0, 0))

// https://github.com/microsoft/TypeScript/issues/33041
function noParams() {}
>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8))

noParams<>();
>noParams : Symbol(noParams, Decl(emptyTypeArgumentList.ts, 1, 8))

10 changes: 9 additions & 1 deletion tests/baselines/reference/emptyTypeArgumentList.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ function foo<T>() { }
>foo : <T>() => void

foo<>();
>foo<>() : any
>foo<>() : void
>foo : <T>() => void

// https://github.com/microsoft/TypeScript/issues/33041
function noParams() {}
>noParams : () => void

noParams<>();
>noParams<>() : void
>noParams : () => void

Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,8): error TS1099: Type argument list cannot be empty.
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(2,9): error TS2558: Expected 1 type arguments, but got 0.
tests/cases/compiler/emptyTypeArgumentListWithNew.ts(6,13): error TS1099: Type argument list cannot be empty.


==== tests/cases/compiler/emptyTypeArgumentListWithNew.ts (2 errors) ====
class foo<T> { }
new foo<>();
~~
!!! error TS1099: Type argument list cannot be empty.

!!! error TS2558: Expected 1 type arguments, but got 0.

// https://github.com/microsoft/TypeScript/issues/33041
class noParams {}
new noParams<>();
~~
!!! error TS1099: Type argument list cannot be empty.
13 changes: 12 additions & 1 deletion tests/baselines/reference/emptyTypeArgumentListWithNew.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//// [emptyTypeArgumentListWithNew.ts]
class foo<T> { }
new foo<>();
new foo<>();

// https://github.com/microsoft/TypeScript/issues/33041
class noParams {}
new noParams<>();

//// [emptyTypeArgumentListWithNew.js]
var foo = /** @class */ (function () {
Expand All @@ -9,3 +13,10 @@ var foo = /** @class */ (function () {
return foo;
}());
new foo();
// https://github.com/microsoft/TypeScript/issues/33041
var noParams = /** @class */ (function () {
function noParams() {
}
return noParams;
}());
new noParams();
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,10 @@ class foo<T> { }
new foo<>();
>foo : Symbol(foo, Decl(emptyTypeArgumentListWithNew.ts, 0, 0))

// https://github.com/microsoft/TypeScript/issues/33041
class noParams {}
>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12))

new noParams<>();
>noParams : Symbol(noParams, Decl(emptyTypeArgumentListWithNew.ts, 1, 12))

10 changes: 9 additions & 1 deletion tests/baselines/reference/emptyTypeArgumentListWithNew.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ class foo<T> { }
>foo : foo<T>

new foo<>();
>new foo<>() : any
>new foo<>() : foo<unknown>
>foo : typeof foo

// https://github.com/microsoft/TypeScript/issues/33041
class noParams {}
>noParams : noParams

new noParams<>();
>new noParams<>() : noParams
>noParams : typeof noParams

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


==== tests/cases/conformance/jsx/file.tsx (14 errors) ====
==== tests/cases/conformance/jsx/file.tsx (12 errors) ====
import React = require('react');

interface Prop {
Expand Down Expand Up @@ -53,14 +51,10 @@ tests/cases/conformance/jsx/file.tsx(53,47): error TS2322: Type 'string' is not
x = <MyComp<> a={10} b="hi" />; // error
~~
!!! error TS1099: Type argument list cannot be empty.

!!! error TS2558: Expected 1 type arguments, but got 0.

x = <MyComp<> a={10} b="hi"></MyComp>; // error
~~
!!! error TS1099: Type argument list cannot be empty.

!!! error TS2558: Expected 1 type arguments, but got 0.

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

Expand Down
6 changes: 5 additions & 1 deletion tests/cases/compiler/emptyTypeArgumentList.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
function foo<T>() { }
foo<>();
foo<>();

// https://github.com/microsoft/TypeScript/issues/33041
function noParams() {}
noParams<>();
6 changes: 5 additions & 1 deletion tests/cases/compiler/emptyTypeArgumentListWithNew.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class foo<T> { }
new foo<>();
new foo<>();

// https://github.com/microsoft/TypeScript/issues/33041
class noParams {}
new noParams<>();