Skip to content

Rearranging members of Array<T> to improve error reporting. #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions src/lib/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,11 +941,24 @@ declare var JSON: JSON;
/////////////////////////////

interface Array<T> {
/**
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
*/
length: number;
/**
* Returns a string representation of an array.
*/
toString(): string;
toLocaleString(): string;
/**
* Appends new elements to an array, and returns the new length of the array.
* @param items New elements of the Array.
*/
push(...items: T[]): number;
/**
* Removes the last element from an array and returns it.
*/
pop(): T;
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
Expand All @@ -961,15 +974,6 @@ interface Array<T> {
* @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.
*/
join(separator?: string): string;
/**
* Removes the last element from an array and returns it.
*/
pop(): T;
/**
* Appends new elements to an array, and returns the new length of the array.
* @param items New elements of the Array.
*/
push(...items: T[]): number;
/**
* Reverses the elements in an Array.
*/
Expand Down Expand Up @@ -1086,11 +1090,6 @@ interface Array<T> {
*/
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;

/**
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
*/
length: number;

[n: number]: T;
}
declare var Array: {
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/arrayAssignmentTest1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,25 +128,25 @@
arr_any = f1; // should be an error - is
~~~~~~~
!!! Type '() => C1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '() => C1'.
!!! Property 'push' is missing in type '() => C1'.
arr_any = o1; // should be an error - is
~~~~~~~
!!! Type '{ one: number; }' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '{ one: number; }'.
!!! Property 'length' is missing in type '{ one: number; }'.
arr_any = a1; // should be ok - is
arr_any = c1; // should be an error - is
~~~~~~~
!!! Type 'C1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C1'.
!!! Property 'length' is missing in type 'C1'.
arr_any = c2; // should be an error - is
~~~~~~~
!!! Type 'C2' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C2'.
!!! Property 'length' is missing in type 'C2'.
arr_any = c3; // should be an error - is
~~~~~~~
!!! Type 'C3' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C3'.
!!! Property 'length' is missing in type 'C3'.
arr_any = i1; // should be an error - is
~~~~~~~
!!! Type 'I1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'I1'.
!!! Property 'length' is missing in type 'I1'.
14 changes: 7 additions & 7 deletions tests/baselines/reference/arrayAssignmentTest2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,30 +64,30 @@
arr_any = f1; // should be an error - is
~~~~~~~
!!! Type '() => C1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '() => C1'.
!!! Property 'push' is missing in type '() => C1'.
arr_any = function () { return null;} // should be an error - is
~~~~~~~
!!! Type '() => any' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '() => any'.
!!! Property 'push' is missing in type '() => any'.
arr_any = o1; // should be an error - is
~~~~~~~
!!! Type '{ one: number; }' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '{ one: number; }'.
!!! Property 'length' is missing in type '{ one: number; }'.
arr_any = a1; // should be ok - is
arr_any = c1; // should be an error - is
~~~~~~~
!!! Type 'C1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C1'.
!!! Property 'length' is missing in type 'C1'.
arr_any = c2; // should be an error - is
~~~~~~~
!!! Type 'C2' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C2'.
!!! Property 'length' is missing in type 'C2'.
arr_any = c3; // should be an error - is
~~~~~~~
!!! Type 'C3' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C3'.
!!! Property 'length' is missing in type 'C3'.
arr_any = i1; // should be an error - is
~~~~~~~
!!! Type 'I1' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'I1'.
!!! Property 'length' is missing in type 'I1'.

4 changes: 2 additions & 2 deletions tests/baselines/reference/arrayAssignmentTest4.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
arr_any = function () { return null;} // should be an error - is
~~~~~~~
!!! Type '() => any' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type '() => any'.
!!! Property 'push' is missing in type '() => any'.
arr_any = c3; // should be an error - is
~~~~~~~
!!! Type 'C3' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'C3'.
!!! Property 'length' is missing in type 'C3'.

2 changes: 1 addition & 1 deletion tests/baselines/reference/arraySigChecking.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
!!! Type 'number[][]' is not assignable to type 'number[][][]':
!!! Type 'number[]' is not assignable to type 'number[][]':
!!! Type 'number' is not assignable to type 'number[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.

function isEmpty(l: { length: number }) {
return l.length === 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: any[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: any[]; }':
!!! Types of property 'two' are incompatible:
!!! Type 'string' is not assignable to type 'any[]':
!!! Property 'join' is missing in type 'String'.
!!! Property 'push' is missing in type 'String'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: number[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'number[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: number[]; }':
!!! Types of property 'two' are incompatible:
!!! Type 'string' is not assignable to type 'number[]':
!!! Types of property 'concat' are incompatible:
!!! Type '(...strings: string[]) => string' is not assignable to type '{ <U extends number[]>(...items: U[]): number[]; (...items: number[]): number[]; }':
!!! Types of parameters 'strings' and 'items' are incompatible:
!!! Type 'string' is not assignable to type 'number'.
!!! Property 'push' is missing in type 'String'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: string[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'string[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: string[]; }':
!!! Types of property 'two' are incompatible:
!!! Type 'string' is not assignable to type 'string[]':
!!! Property 'join' is missing in type 'String'.
!!! Property 'push' is missing in type 'String'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: boolean[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'boolean[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ two: boolean[]; }':
!!! Types of property 'two' are incompatible:
!!! Type 'string' is not assignable to type 'boolean[]':
!!! Types of property 'concat' are incompatible:
!!! Type '(...strings: string[]) => string' is not assignable to type '{ <U extends boolean[]>(...items: U[]): boolean[]; (...items: boolean[]): boolean[]; }':
!!! Types of parameters 'strings' and 'items' are incompatible:
!!! Type 'string' is not assignable to type 'boolean'.
!!! Property 'push' is missing in type 'String'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: any[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'any[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: number[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'number[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: string[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'string[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
!!! Type 'interfaceWithPublicAndOptional<number, string>' is not assignable to type '{ one: boolean[]; }':
!!! Types of property 'one' are incompatible:
!!! Type 'number' is not assignable to type 'boolean[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
2 changes: 1 addition & 1 deletion tests/baselines/reference/enumAssignability.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
var m: number[] = e;
~
!!! Type 'E' is not assignable to type 'number[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
var n: { foo: string } = e;
~
!!! Type 'E' is not assignable to type '{ foo: string; }':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
!!! Cannot compile external modules unless the '--module' flag is provided.
~~~~~~~~~~~~~~~
!!! Class 'ObservableArray<T>' incorrectly implements interface 'T[]':
!!! Property 'join' is missing in type 'ObservableArray<T>'.
!!! Property 'length' is missing in type 'ObservableArray<T>'.
concat<U extends T[]>(...items: U[]): T[];
concat(...items: T[]): T[];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/qualify.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
var v3:K1.I3[]=v1;
~~
!!! Type 'I4' is not assignable to type 'I3[]':
!!! Property 'concat' is missing in type 'I4'.
!!! Property 'length' is missing in type 'I4'.
var v4:()=>K1.I3=v1;
~~
!!! Type 'I4' is not assignable to type '() => I3'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
!!! Type '(...x: number[]) => void' is not assignable to type '(x: number[], y: string) => void':
!!! Types of parameters 'x' and 'x' are incompatible:
!!! Type 'number' is not assignable to type 'number[]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
n([4], 'foo');

6 changes: 3 additions & 3 deletions tests/baselines/reference/typeName1.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@
var x10:I[][][][]=3;
~~~
!!! Type 'number' is not assignable to type 'I[][][][]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
var x11:{z:I;x:boolean;}[][]=3;
~~~
!!! Type 'number' is not assignable to type '{ z: I; x: boolean; }[][]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
var x12:{z:I;x:boolean;y:(s:string)=>boolean;w:{ z:I;[s:string]:{ x; y; };[n:number]:{x; y;};():boolean; };}[][]=3;
~~~
!!! Type 'number' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [x: string]: { x: any; y: any; }; [x: number]: { x: any; y: any; }; z: I; }; }[][]':
!!! Property 'concat' is missing in type 'Number'.
!!! Property 'length' is missing in type 'Number'.
var x13:{ new(): number; new(n:number):number; x: string; w: {y: number;}; (): {}; } = 3;
~~~
!!! Type 'number' is not assignable to type '{ (): {}; new (): number; new (n: number): number; x: string; w: { y: number; }; }':
Expand Down