Skip to content

Commit e0a4b3c

Browse files
committed
Rearranging members of Array<T> to improve error reporting.
1 parent 349367d commit e0a4b3c

22 files changed

+48
-55
lines changed

src/lib/core.d.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -941,11 +941,24 @@ declare var JSON: JSON;
941941
/////////////////////////////
942942

943943
interface Array<T> {
944+
/**
945+
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
946+
*/
947+
length: number;
944948
/**
945949
* Returns a string representation of an array.
946950
*/
947951
toString(): string;
948952
toLocaleString(): string;
953+
/**
954+
* Appends new elements to an array, and returns the new length of the array.
955+
* @param items New elements of the Array.
956+
*/
957+
push(...items: T[]): number;
958+
/**
959+
* Removes the last element from an array and returns it.
960+
*/
961+
pop(): T;
949962
/**
950963
* Combines two or more arrays.
951964
* @param items Additional items to add to the end of array1.
@@ -961,15 +974,6 @@ interface Array<T> {
961974
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
962975
*/
963976
join(separator?: string): string;
964-
/**
965-
* Removes the last element from an array and returns it.
966-
*/
967-
pop(): T;
968-
/**
969-
* Appends new elements to an array, and returns the new length of the array.
970-
* @param items New elements of the Array.
971-
*/
972-
push(...items: T[]): number;
973977
/**
974978
* Reverses the elements in an Array.
975979
*/
@@ -1086,11 +1090,6 @@ interface Array<T> {
10861090
*/
10871091
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
10881092

1089-
/**
1090-
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
1091-
*/
1092-
length: number;
1093-
10941093
[n: number]: T;
10951094
}
10961095
declare var Array: {

tests/baselines/reference/arrayAssignmentTest1.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,25 @@
128128
arr_any = f1; // should be an error - is
129129
~~~~~~~
130130
!!! Type '() => C1' is not assignable to type 'any[]':
131-
!!! Property 'concat' is missing in type '() => C1'.
131+
!!! Property 'push' is missing in type '() => C1'.
132132
arr_any = o1; // should be an error - is
133133
~~~~~~~
134134
!!! Type '{ one: number; }' is not assignable to type 'any[]':
135-
!!! Property 'concat' is missing in type '{ one: number; }'.
135+
!!! Property 'length' is missing in type '{ one: number; }'.
136136
arr_any = a1; // should be ok - is
137137
arr_any = c1; // should be an error - is
138138
~~~~~~~
139139
!!! Type 'C1' is not assignable to type 'any[]':
140-
!!! Property 'concat' is missing in type 'C1'.
140+
!!! Property 'length' is missing in type 'C1'.
141141
arr_any = c2; // should be an error - is
142142
~~~~~~~
143143
!!! Type 'C2' is not assignable to type 'any[]':
144-
!!! Property 'concat' is missing in type 'C2'.
144+
!!! Property 'length' is missing in type 'C2'.
145145
arr_any = c3; // should be an error - is
146146
~~~~~~~
147147
!!! Type 'C3' is not assignable to type 'any[]':
148-
!!! Property 'concat' is missing in type 'C3'.
148+
!!! Property 'length' is missing in type 'C3'.
149149
arr_any = i1; // should be an error - is
150150
~~~~~~~
151151
!!! Type 'I1' is not assignable to type 'any[]':
152-
!!! Property 'concat' is missing in type 'I1'.
152+
!!! Property 'length' is missing in type 'I1'.

tests/baselines/reference/arrayAssignmentTest2.errors.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,30 @@
6464
arr_any = f1; // should be an error - is
6565
~~~~~~~
6666
!!! Type '() => C1' is not assignable to type 'any[]':
67-
!!! Property 'concat' is missing in type '() => C1'.
67+
!!! Property 'push' is missing in type '() => C1'.
6868
arr_any = function () { return null;} // should be an error - is
6969
~~~~~~~
7070
!!! Type '() => any' is not assignable to type 'any[]':
71-
!!! Property 'concat' is missing in type '() => any'.
71+
!!! Property 'push' is missing in type '() => any'.
7272
arr_any = o1; // should be an error - is
7373
~~~~~~~
7474
!!! Type '{ one: number; }' is not assignable to type 'any[]':
75-
!!! Property 'concat' is missing in type '{ one: number; }'.
75+
!!! Property 'length' is missing in type '{ one: number; }'.
7676
arr_any = a1; // should be ok - is
7777
arr_any = c1; // should be an error - is
7878
~~~~~~~
7979
!!! Type 'C1' is not assignable to type 'any[]':
80-
!!! Property 'concat' is missing in type 'C1'.
80+
!!! Property 'length' is missing in type 'C1'.
8181
arr_any = c2; // should be an error - is
8282
~~~~~~~
8383
!!! Type 'C2' is not assignable to type 'any[]':
84-
!!! Property 'concat' is missing in type 'C2'.
84+
!!! Property 'length' is missing in type 'C2'.
8585
arr_any = c3; // should be an error - is
8686
~~~~~~~
8787
!!! Type 'C3' is not assignable to type 'any[]':
88-
!!! Property 'concat' is missing in type 'C3'.
88+
!!! Property 'length' is missing in type 'C3'.
8989
arr_any = i1; // should be an error - is
9090
~~~~~~~
9191
!!! Type 'I1' is not assignable to type 'any[]':
92-
!!! Property 'concat' is missing in type 'I1'.
92+
!!! Property 'length' is missing in type 'I1'.
9393

tests/baselines/reference/arrayAssignmentTest4.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
arr_any = function () { return null;} // should be an error - is
2626
~~~~~~~
2727
!!! Type '() => any' is not assignable to type 'any[]':
28-
!!! Property 'concat' is missing in type '() => any'.
28+
!!! Property 'push' is missing in type '() => any'.
2929
arr_any = c3; // should be an error - is
3030
~~~~~~~
3131
!!! Type 'C3' is not assignable to type 'any[]':
32-
!!! Property 'concat' is missing in type 'C3'.
32+
!!! Property 'length' is missing in type 'C3'.
3333

tests/baselines/reference/arraySigChecking.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
!!! Type 'number[][]' is not assignable to type 'number[][][]':
3131
!!! Type 'number[]' is not assignable to type 'number[][]':
3232
!!! Type 'number' is not assignable to type 'number[]':
33-
!!! Property 'concat' is missing in type 'Number'.
33+
!!! Property 'length' is missing in type 'Number'.
3434

3535
function isEmpty(l: { length: number }) {
3636
return l.length === 0;

tests/baselines/reference/assignmentCompatability16.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: any[]; }':
1313
!!! Types of property 'one' are incompatible:
1414
!!! Type 'number' is not assignable to type 'any[]':
15-
!!! Property 'concat' is missing in type 'Number'.
15+
!!! Property 'length' is missing in type 'Number'.

tests/baselines/reference/assignmentCompatability17.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: any[]; }':
1313
!!! Types of property 'two' are incompatible:
1414
!!! Type 'string' is not assignable to type 'any[]':
15-
!!! Property 'join' is missing in type 'String'.
15+
!!! Property 'push' is missing in type 'String'.

tests/baselines/reference/assignmentCompatability18.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: number[]; }':
1313
!!! Types of property 'one' are incompatible:
1414
!!! Type 'number' is not assignable to type 'number[]':
15-
!!! Property 'concat' is missing in type 'Number'.
15+
!!! Property 'length' is missing in type 'Number'.

tests/baselines/reference/assignmentCompatability19.errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,4 @@
1212
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: number[]; }':
1313
!!! Types of property 'two' are incompatible:
1414
!!! Type 'string' is not assignable to type 'number[]':
15-
!!! Types of property 'concat' are incompatible:
16-
!!! Type '(...strings: string[]) => string' is not assignable to type '{ <U extends number[]>(...items: U[]): number[]; (...items: number[]): number[]; }':
17-
!!! Types of parameters 'strings' and 'items' are incompatible:
18-
!!! Type 'string' is not assignable to type 'number'.
15+
!!! Property 'push' is missing in type 'String'.

tests/baselines/reference/assignmentCompatability20.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: string[]; }':
1313
!!! Types of property 'one' are incompatible:
1414
!!! Type 'number' is not assignable to type 'string[]':
15-
!!! Property 'concat' is missing in type 'Number'.
15+
!!! Property 'length' is missing in type 'Number'.

0 commit comments

Comments
 (0)