Fix exceptions on empty tuple errors (#17311)

* Fix exceptions on empty tuple errors

* Remove bonus semicolon

* Invert condition
This commit is contained in:
Wesley Wigham
2017-07-20 10:09:55 -07:00
committed by GitHub
parent 1f09af9ab6
commit 7cb8ce4346
7 changed files with 55 additions and 2 deletions

View File

@@ -2621,9 +2621,10 @@ namespace ts {
return createTupleTypeNode(tupleConstituentNodes);
}
}
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
context.encounteredError = true;
if (context.encounteredError || (context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
return createTupleTypeNode([]);
}
context.encounteredError = true;
return undefined;
}
else {

View File

@@ -0,0 +1,8 @@
tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS2538: Type '[]' cannot be used as an index type.
==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (1 errors) ====
var x: any[[]];
~~
!!! error TS2538: Type '[]' cannot be used as an index type.

View File

@@ -0,0 +1,6 @@
//// [anyIndexedAccessArrayNoException.ts]
var x: any[[]];
//// [anyIndexedAccessArrayNoException.js]
var x;

View File

@@ -0,0 +1,20 @@
tests/cases/compiler/promiseEmptyTupleNoException.ts(1,38): error TS1122: A tuple type element list cannot be empty.
tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'.
Types of property 'pop' are incompatible.
Type '() => any' is not assignable to type '() => never'.
Type 'any' is not assignable to type 'never'.
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (2 errors) ====
export async function get(): Promise<[]> {
~~
!!! error TS1122: A tuple type element list cannot be empty.
let emails = [];
return emails;
~~~~~~~~~~~~~~
!!! error TS2322: Type 'any[]' is not assignable to type '[]'.
!!! error TS2322: Types of property 'pop' are incompatible.
!!! error TS2322: Type '() => any' is not assignable to type '() => never'.
!!! error TS2322: Type 'any' is not assignable to type 'never'.
}

View File

@@ -0,0 +1,12 @@
//// [promiseEmptyTupleNoException.ts]
export async function get(): Promise<[]> {
let emails = [];
return emails;
}
//// [promiseEmptyTupleNoException.js]
export async function get() {
let emails = [];
return emails;
}

View File

@@ -0,0 +1 @@
var x: any[[]];

View File

@@ -0,0 +1,5 @@
// @target: es2017
export async function get(): Promise<[]> {
let emails = [];
return emails;
}