From e0a4b3c1cca9b8fc450d7f4825c443f9ac9ecd41 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 12 Aug 2014 11:13:15 -0700 Subject: [PATCH] Rearranging members of Array to improve error reporting. --- src/lib/core.d.ts | 27 +++++++++---------- .../reference/arrayAssignmentTest1.errors.txt | 12 ++++----- .../reference/arrayAssignmentTest2.errors.txt | 14 +++++----- .../reference/arrayAssignmentTest4.errors.txt | 4 +-- .../reference/arraySigChecking.errors.txt | 2 +- .../assignmentCompatability16.errors.txt | 2 +- .../assignmentCompatability17.errors.txt | 2 +- .../assignmentCompatability18.errors.txt | 2 +- .../assignmentCompatability19.errors.txt | 5 +--- .../assignmentCompatability20.errors.txt | 2 +- .../assignmentCompatability21.errors.txt | 2 +- .../assignmentCompatability22.errors.txt | 2 +- .../assignmentCompatability23.errors.txt | 5 +--- .../assignmentCompatability29.errors.txt | 2 +- .../assignmentCompatability30.errors.txt | 2 +- .../assignmentCompatability31.errors.txt | 2 +- .../assignmentCompatability32.errors.txt | 2 +- .../reference/enumAssignability.errors.txt | 2 +- .../genericArrayExtenstions.errors.txt | 2 +- tests/baselines/reference/qualify.errors.txt | 2 +- .../restArgAssignmentCompat.errors.txt | 2 +- .../baselines/reference/typeName1.errors.txt | 6 ++--- 22 files changed, 48 insertions(+), 55 deletions(-) diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 607f6678c1a04..8e16e4bdd6cd5 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -941,11 +941,24 @@ declare var JSON: JSON; ///////////////////////////// interface Array { + /** + * 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. @@ -961,15 +974,6 @@ interface Array { * @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. */ @@ -1086,11 +1090,6 @@ interface Array { */ reduceRight(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: { diff --git a/tests/baselines/reference/arrayAssignmentTest1.errors.txt b/tests/baselines/reference/arrayAssignmentTest1.errors.txt index 0f1807e8b2669..e14bacb3cb4c1 100644 --- a/tests/baselines/reference/arrayAssignmentTest1.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest1.errors.txt @@ -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'. \ No newline at end of file +!!! Property 'length' is missing in type 'I1'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayAssignmentTest2.errors.txt b/tests/baselines/reference/arrayAssignmentTest2.errors.txt index fd3988ca4d86f..5ecebfe392ab8 100644 --- a/tests/baselines/reference/arrayAssignmentTest2.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest2.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/arrayAssignmentTest4.errors.txt b/tests/baselines/reference/arrayAssignmentTest4.errors.txt index ef56c1b528f5a..210e18dfe873a 100644 --- a/tests/baselines/reference/arrayAssignmentTest4.errors.txt +++ b/tests/baselines/reference/arrayAssignmentTest4.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/arraySigChecking.errors.txt b/tests/baselines/reference/arraySigChecking.errors.txt index 7edce0be793b1..3cb48f7a4e9b2 100644 --- a/tests/baselines/reference/arraySigChecking.errors.txt +++ b/tests/baselines/reference/arraySigChecking.errors.txt @@ -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; diff --git a/tests/baselines/reference/assignmentCompatability16.errors.txt b/tests/baselines/reference/assignmentCompatability16.errors.txt index 72ba13966ecf8..0e8b5b045a684 100644 --- a/tests/baselines/reference/assignmentCompatability16.errors.txt +++ b/tests/baselines/reference/assignmentCompatability16.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability17.errors.txt b/tests/baselines/reference/assignmentCompatability17.errors.txt index 0f2560609a843..ddf7bddabf898 100644 --- a/tests/baselines/reference/assignmentCompatability17.errors.txt +++ b/tests/baselines/reference/assignmentCompatability17.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'push' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability18.errors.txt b/tests/baselines/reference/assignmentCompatability18.errors.txt index 2e63e9c002451..26f5fa6ede1e2 100644 --- a/tests/baselines/reference/assignmentCompatability18.errors.txt +++ b/tests/baselines/reference/assignmentCompatability18.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability19.errors.txt b/tests/baselines/reference/assignmentCompatability19.errors.txt index ce8beff52c8b8..cdfcf84aae94e 100644 --- a/tests/baselines/reference/assignmentCompatability19.errors.txt +++ b/tests/baselines/reference/assignmentCompatability19.errors.txt @@ -12,7 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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 '{ (...items: U[]): number[]; (...items: number[]): number[]; }': -!!! Types of parameters 'strings' and 'items' are incompatible: -!!! Type 'string' is not assignable to type 'number'. \ No newline at end of file +!!! Property 'push' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability20.errors.txt b/tests/baselines/reference/assignmentCompatability20.errors.txt index 6a4cdd046b6c1..0a198da552307 100644 --- a/tests/baselines/reference/assignmentCompatability20.errors.txt +++ b/tests/baselines/reference/assignmentCompatability20.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability21.errors.txt b/tests/baselines/reference/assignmentCompatability21.errors.txt index 9da82d08a6198..e8785413e05da 100644 --- a/tests/baselines/reference/assignmentCompatability21.errors.txt +++ b/tests/baselines/reference/assignmentCompatability21.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'push' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability22.errors.txt b/tests/baselines/reference/assignmentCompatability22.errors.txt index 1f707044005bf..6497d477102ec 100644 --- a/tests/baselines/reference/assignmentCompatability22.errors.txt +++ b/tests/baselines/reference/assignmentCompatability22.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability23.errors.txt b/tests/baselines/reference/assignmentCompatability23.errors.txt index 31f58604289c5..88f13a2ffc2ef 100644 --- a/tests/baselines/reference/assignmentCompatability23.errors.txt +++ b/tests/baselines/reference/assignmentCompatability23.errors.txt @@ -12,7 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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 '{ (...items: U[]): boolean[]; (...items: boolean[]): boolean[]; }': -!!! Types of parameters 'strings' and 'items' are incompatible: -!!! Type 'string' is not assignable to type 'boolean'. \ No newline at end of file +!!! Property 'push' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability29.errors.txt b/tests/baselines/reference/assignmentCompatability29.errors.txt index 24b2287c57a04..937d511200703 100644 --- a/tests/baselines/reference/assignmentCompatability29.errors.txt +++ b/tests/baselines/reference/assignmentCompatability29.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability30.errors.txt b/tests/baselines/reference/assignmentCompatability30.errors.txt index 1f93bccf20364..08a8b313d303e 100644 --- a/tests/baselines/reference/assignmentCompatability30.errors.txt +++ b/tests/baselines/reference/assignmentCompatability30.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability31.errors.txt b/tests/baselines/reference/assignmentCompatability31.errors.txt index 274ec67a1429e..c620198e2ac45 100644 --- a/tests/baselines/reference/assignmentCompatability31.errors.txt +++ b/tests/baselines/reference/assignmentCompatability31.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability32.errors.txt b/tests/baselines/reference/assignmentCompatability32.errors.txt index 9f979a127c48d..a20461b25bde0 100644 --- a/tests/baselines/reference/assignmentCompatability32.errors.txt +++ b/tests/baselines/reference/assignmentCompatability32.errors.txt @@ -12,4 +12,4 @@ !!! Type 'interfaceWithPublicAndOptional' 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'. \ No newline at end of file +!!! Property 'length' is missing in type 'Number'. \ No newline at end of file diff --git a/tests/baselines/reference/enumAssignability.errors.txt b/tests/baselines/reference/enumAssignability.errors.txt index 4c6ecbc83dd37..3a581b3cd1a30 100644 --- a/tests/baselines/reference/enumAssignability.errors.txt +++ b/tests/baselines/reference/enumAssignability.errors.txt @@ -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; }': diff --git a/tests/baselines/reference/genericArrayExtenstions.errors.txt b/tests/baselines/reference/genericArrayExtenstions.errors.txt index ff9836843c93e..c13b637a39299 100644 --- a/tests/baselines/reference/genericArrayExtenstions.errors.txt +++ b/tests/baselines/reference/genericArrayExtenstions.errors.txt @@ -4,7 +4,7 @@ !!! Cannot compile external modules unless the '--module' flag is provided. ~~~~~~~~~~~~~~~ !!! Class 'ObservableArray' incorrectly implements interface 'T[]': -!!! Property 'join' is missing in type 'ObservableArray'. +!!! Property 'length' is missing in type 'ObservableArray'. concat(...items: U[]): T[]; concat(...items: T[]): T[]; } diff --git a/tests/baselines/reference/qualify.errors.txt b/tests/baselines/reference/qualify.errors.txt index 4cd1368dc0efa..c957822849ae7 100644 --- a/tests/baselines/reference/qualify.errors.txt +++ b/tests/baselines/reference/qualify.errors.txt @@ -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'. diff --git a/tests/baselines/reference/restArgAssignmentCompat.errors.txt b/tests/baselines/reference/restArgAssignmentCompat.errors.txt index f97fc72413454..66723128a2d24 100644 --- a/tests/baselines/reference/restArgAssignmentCompat.errors.txt +++ b/tests/baselines/reference/restArgAssignmentCompat.errors.txt @@ -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'); \ No newline at end of file diff --git a/tests/baselines/reference/typeName1.errors.txt b/tests/baselines/reference/typeName1.errors.txt index 26a744f7d2d18..92b3279ab812d 100644 --- a/tests/baselines/reference/typeName1.errors.txt +++ b/tests/baselines/reference/typeName1.errors.txt @@ -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; }; }':