Skip to content

Commit 665f44f

Browse files
ditch empty tuple check
1 parent d03d107 commit 665f44f

15 files changed

+56
-47
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2646,11 +2646,7 @@ namespace ts {
26462646
return createTupleTypeNode(tupleConstituentNodes);
26472647
}
26482648
}
2649-
if (context.encounteredError || (context.flags & NodeBuilderFlags.AllowEmptyTuple)) {
2650-
return createTupleTypeNode([]);
2651-
}
2652-
context.encounteredError = true;
2653-
return undefined;
2649+
return createTupleTypeNode([]);
26542650
}
26552651
else {
26562652
const outerTypeParameters = type.target.outerTypeParameters;
@@ -18737,10 +18733,6 @@ namespace ts {
1873718733
function checkTupleType(node: TupleTypeNode) {
1873818734
// Grammar checking
1873918735
const hasErrorFromDisallowedTrailingComma = checkGrammarForDisallowedTrailingComma(node.elementTypes);
18740-
if (!hasErrorFromDisallowedTrailingComma && node.elementTypes.length === 0) {
18741-
grammarErrorOnNode(node, Diagnostics.A_tuple_type_element_list_cannot_be_empty);
18742-
}
18743-
1874418736
forEach(node.elementTypes, checkSourceElement);
1874518737
}
1874618738

src/compiler/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,9 +2651,9 @@ namespace ts {
26512651
AllowQualifedNameInPlaceOfIdentifier = 1 << 11,
26522652
AllowAnonymousIdentifier = 1 << 13,
26532653
AllowEmptyUnionOrIntersection = 1 << 14,
2654-
AllowEmptyTuple = 1 << 15,
2654+
// AllowEmptyTuple = 1 << 15,
26552655

2656-
IgnoreErrors = AllowThisInObjectLiteral | AllowQualifedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple,
2656+
IgnoreErrors = AllowThisInObjectLiteral | AllowQualifedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection,
26572657

26582658
// State
26592659
InObjectTypeLiteral = 1 << 20,

tests/baselines/reference/TupleType3.errors.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/parser/ecmascript5/TupleTypes/TupleType3.ts ===
2+
var v: []
3+
>v : Symbol(v, Decl(TupleType3.ts, 0, 3))
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
=== tests/cases/conformance/parser/ecmascript5/TupleTypes/TupleType3.ts ===
2+
var v: []
3+
>v : []
4+
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS1122: A tuple type element list cannot be empty.
21
tests/cases/compiler/anyIndexedAccessArrayNoException.ts(1,12): error TS2538: Type '[]' cannot be used as an index type.
32

43

5-
==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (2 errors) ====
4+
==== tests/cases/compiler/anyIndexedAccessArrayNoException.ts (1 errors) ====
65
var x: any[[]];
76
~~
8-
!!! error TS1122: A tuple type element list cannot be empty.
9-
~~
107
!!! error TS2538: Type '[]' cannot be used as an index type.
118

tests/baselines/reference/emptyTuplesTypeAssertion01.errors.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion01.ts ===
2+
let x = <[]>[];
3+
>x : Symbol(x, Decl(emptyTuplesTypeAssertion01.ts, 0, 3))
4+
5+
let y = x[0];
6+
>y : Symbol(y, Decl(emptyTuplesTypeAssertion01.ts, 1, 3))
7+
>x : Symbol(x, Decl(emptyTuplesTypeAssertion01.ts, 0, 3))
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion01.ts ===
2+
let x = <[]>[];
3+
>x : []
4+
><[]>[] : []
5+
>[] : undefined[]
6+
7+
let y = x[0];
8+
>y : never
9+
>x[0] : never
10+
>x : []
11+
>0 : 0
12+

tests/baselines/reference/emptyTuplesTypeAssertion02.errors.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion02.ts ===
2+
let x = [] as [];
3+
>x : Symbol(x, Decl(emptyTuplesTypeAssertion02.ts, 0, 3))
4+
5+
let y = x[0];
6+
>y : Symbol(y, Decl(emptyTuplesTypeAssertion02.ts, 1, 3))
7+
>x : Symbol(x, Decl(emptyTuplesTypeAssertion02.ts, 0, 3))
8+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/types/tuple/emptyTuples/emptyTuplesTypeAssertion02.ts ===
2+
let x = [] as [];
3+
>x : []
4+
>[] as [] : []
5+
>[] : undefined[]
6+
7+
let y = x[0];
8+
>y : never
9+
>x[0] : never
10+
>x : []
11+
>0 : 0
12+

tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(35,21): error
1515
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(36,21): error TS2538: Type 'boolean' cannot be used as an index type.
1616
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(41,31): error TS2538: Type 'boolean' cannot be used as an index type.
1717
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(46,16): error TS2538: Type 'boolean' cannot be used as an index type.
18-
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(49,12): error TS1122: A tuple type element list cannot be empty.
1918
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(63,33): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
2019
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
2120
Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
@@ -29,7 +28,7 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(76,5): error
2928
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(77,5): error TS2322: Type 'keyof (T & U)' is not assignable to type 'keyof (T | U)'.
3029

3130

32-
==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (25 errors) ====
31+
==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (24 errors) ====
3332
class Shape {
3433
name: string;
3534
width: number;
@@ -113,8 +112,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(77,5): error
113112

114113
type T60 = {}["toString"];
115114
type T61 = []["toString"];
116-
~~
117-
!!! error TS1122: A tuple type element list cannot be empty.
118115

119116
declare let cond: boolean;
120117

tests/baselines/reference/promiseEmptyTupleNoException.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
tests/cases/compiler/promiseEmptyTupleNoException.ts(1,38): error TS1122: A tuple type element list cannot be empty.
21
tests/cases/compiler/promiseEmptyTupleNoException.ts(3,3): error TS2322: Type 'any[]' is not assignable to type '[]'.
32
Types of property 'pop' are incompatible.
43
Type '() => any' is not assignable to type '() => never'.
54
Type 'any' is not assignable to type 'never'.
65

76

8-
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (2 errors) ====
7+
==== tests/cases/compiler/promiseEmptyTupleNoException.ts (1 errors) ====
98
export async function get(): Promise<[]> {
10-
~~
11-
!!! error TS1122: A tuple type element list cannot be empty.
129
let emails = [];
1310
return emails;
1411
~~~~~~~~~~~~~~

tests/cases/compiler/tupleTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
var v1: []; // Error
1+
var v1: [] = [];
22
var v2: [number];
33
var v3: [number, string];
44
var v4: [number, [string, string]];
5+
var v5: number[] = v1;
56

67
var t: [number, string];
78
var t0 = t[0]; // number

0 commit comments

Comments
 (0)