mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 01:49:41 -05:00
Fix exceptions on empty tuple errors (#17311)
* Fix exceptions on empty tuple errors * Remove bonus semicolon * Invert condition
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
//// [anyIndexedAccessArrayNoException.ts]
|
||||
var x: any[[]];
|
||||
|
||||
|
||||
//// [anyIndexedAccessArrayNoException.js]
|
||||
var x;
|
||||
@@ -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'.
|
||||
}
|
||||
|
||||
12
tests/baselines/reference/promiseEmptyTupleNoException.js
Normal file
12
tests/baselines/reference/promiseEmptyTupleNoException.js
Normal 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;
|
||||
}
|
||||
1
tests/cases/compiler/anyIndexedAccessArrayNoException.ts
Normal file
1
tests/cases/compiler/anyIndexedAccessArrayNoException.ts
Normal file
@@ -0,0 +1 @@
|
||||
var x: any[[]];
|
||||
5
tests/cases/compiler/promiseEmptyTupleNoException.ts
Normal file
5
tests/cases/compiler/promiseEmptyTupleNoException.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
// @target: es2017
|
||||
export async function get(): Promise<[]> {
|
||||
let emails = [];
|
||||
return emails;
|
||||
}
|
||||
Reference in New Issue
Block a user