Skip to content

Commit 7cb8ce4

Browse files
authored
Fix exceptions on empty tuple errors (microsoft#17311)
* Fix exceptions on empty tuple errors * Remove bonus semicolon * Invert condition
1 parent 1f09af9 commit 7cb8ce4

7 files changed

Lines changed: 55 additions & 2 deletions

src/compiler/checker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,9 +2621,10 @@ namespace ts {
26212621
return createTupleTypeNode(tupleConstituentNodes);
26222622
}
26232623
}
2624-
if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
2625-
context.encounteredError = true;
2624+
if (context.encounteredError || (context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
2625+
return createTupleTypeNode([]);
26262626
}
2627+
context.encounteredError = true;
26272628
return undefined;
26282629
}
26292630
else {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS2538: Type '[]' cannot be used as an index type.
2+
3+
4+
==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (1 errors) ====
5+
var x: any[[]];
6+
~~
7+
!!! error TS2538: Type '[]' cannot be used as an index type.
8+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [anyIndexedAccessArrayNoException.ts]
2+
var x: any[[]];
3+
4+
5+
//// [anyIndexedAccessArrayNoException.js]
6+
var x;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tests/cases/compiler/promiseEmptyTupleNoException.ts(1,38): error TS1122: A tuple type element list cannot be empty.
2+
tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'.
3+
Types of property 'pop' are incompatible.
4+
Type '() => any' is not assignable to type '() => never'.
5+
Type 'any' is not assignable to type 'never'.
6+
7+
8+
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (2 errors) ====
9+
export async function get(): Promise<[]> {
10+
~~
11+
!!! error TS1122: A tuple type element list cannot be empty.
12+
let emails = [];
13+
return emails;
14+
~~~~~~~~~~~~~~
15+
!!! error TS2322: Type 'any[]' is not assignable to type '[]'.
16+
!!! error TS2322: Types of property 'pop' are incompatible.
17+
!!! error TS2322: Type '() => any' is not assignable to type '() => never'.
18+
!!! error TS2322: Type 'any' is not assignable to type 'never'.
19+
}
20+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [promiseEmptyTupleNoException.ts]
2+
export async function get(): Promise<[]> {
3+
let emails = [];
4+
return emails;
5+
}
6+
7+
8+
//// [promiseEmptyTupleNoException.js]
9+
export async function get() {
10+
let emails = [];
11+
return emails;
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var x: any[[]];
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @target: es2017
2+
export async function get(): Promise<[]> {
3+
let emails = [];
4+
return emails;
5+
}

0 commit comments

Comments
 (0)