Skip to content

Commit 93ab352

Browse files
Merge pull request #25565 from Microsoft/popFirst
Make 'pop' the first method that uses 'T' in 'Array'
2 parents afdd47c + 751bceb commit 93ab352

14 files changed

+186
-35
lines changed

src/lib/es5.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,15 +1125,15 @@ interface Array<T> {
11251125
* Returns a string representation of an array. The elements are converted to string using their toLocalString methods.
11261126
*/
11271127
toLocaleString(): string;
1128+
/**
1129+
* Removes the last element from an array and returns it.
1130+
*/
1131+
pop(): T | undefined;
11281132
/**
11291133
* Appends new elements to an array, and returns the new length of the array.
11301134
* @param items New elements of the Array.
11311135
*/
11321136
push(...items: T[]): number;
1133-
/**
1134-
* Removes the last element from an array and returns it.
1135-
*/
1136-
pop(): T | undefined;
11371137
/**
11381138
* Combines two or more arrays.
11391139
* @param items Additional items to add to the end of array1.

tests/baselines/reference/arityAndOrderCompatibility01.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error
2121
Types of property '0' are incompatible.
2222
Type 'string' is not assignable to type 'number'.
2323
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'.
24-
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
24+
Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
2525
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'.
2626
Types of property 'length' are incompatible.
2727
Type '2' is not assignable to type '1'.
2828
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'.
2929
Types of property 'length' are incompatible.
3030
Type '2' is not assignable to type '1'.
3131
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'.
32-
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
32+
Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
3333
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
3434
Type 'string' is not assignable to type 'number'.
3535
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(31,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'.
3636
Types of property '0' are incompatible.
3737
Type 'string' is not assignable to type 'number'.
3838
tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'.
39-
Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
39+
Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
4040

4141

4242
==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (19 errors) ====
@@ -102,7 +102,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
102102
var l3: [number] = z;
103103
~~
104104
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number]'.
105-
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
105+
!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
106106
var m1: [string] = x;
107107
~~
108108
!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'.
@@ -116,7 +116,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
116116
var m3: [string] = z;
117117
~~
118118
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[string]'.
119-
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
119+
!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
120120
var n1: [number, string] = x;
121121
~~
122122
!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'.
@@ -129,7 +129,7 @@ tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(32,5): error
129129
var n3: [number, string] = z;
130130
~~
131131
!!! error TS2322: Type '{ 0: string; 1: number; length: 2; }' is not assignable to type '[number, string]'.
132-
!!! error TS2322: Property 'push' is missing in type '{ 0: string; 1: number; length: 2; }'.
132+
!!! error TS2322: Property 'pop' is missing in type '{ 0: string; 1: number; length: 2; }'.
133133
var o1: [string, number] = x;
134134
var o2: [string, number] = y;
135135
var o3: [string, number] = y;

tests/baselines/reference/arrayAssignmentTest1.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ tests/cases/compiler/arrayAssignmentTest1.ts(77,1): error TS2322: Type 'I1[]' is
3434
Type 'I1' is not assignable to type 'C3'.
3535
Property 'CM3M1' is missing in type 'I1'.
3636
tests/cases/compiler/arrayAssignmentTest1.ts(79,1): error TS2322: Type '() => C1' is not assignable to type 'any[]'.
37-
Property 'push' is missing in type '() => C1'.
37+
Property 'pop' is missing in type '() => C1'.
3838
tests/cases/compiler/arrayAssignmentTest1.ts(80,1): error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'.
3939
Property 'length' is missing in type '{ one: number; }'.
4040
tests/cases/compiler/arrayAssignmentTest1.ts(82,1): error TS2322: Type 'C1' is not assignable to type 'any[]'.
@@ -177,7 +177,7 @@ tests/cases/compiler/arrayAssignmentTest1.ts(85,1): error TS2322: Type 'I1' is n
177177
arr_any = f1; // should be an error - is
178178
~~~~~~~
179179
!!! error TS2322: Type '() => C1' is not assignable to type 'any[]'.
180-
!!! error TS2322: Property 'push' is missing in type '() => C1'.
180+
!!! error TS2322: Property 'pop' is missing in type '() => C1'.
181181
arr_any = o1; // should be an error - is
182182
~~~~~~~
183183
!!! error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'.

tests/baselines/reference/arrayAssignmentTest2.errors.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ tests/cases/compiler/arrayAssignmentTest2.ts(49,1): error TS2322: Type 'I1[]' is
88
Type 'I1' is not assignable to type 'C3'.
99
Property 'CM3M1' is missing in type 'I1'.
1010
tests/cases/compiler/arrayAssignmentTest2.ts(51,1): error TS2322: Type '() => C1' is not assignable to type 'any[]'.
11-
Property 'push' is missing in type '() => C1'.
11+
Property 'pop' is missing in type '() => C1'.
1212
tests/cases/compiler/arrayAssignmentTest2.ts(52,1): error TS2322: Type '() => any' is not assignable to type 'any[]'.
13-
Property 'push' is missing in type '() => any'.
13+
Property 'pop' is missing in type '() => any'.
1414
tests/cases/compiler/arrayAssignmentTest2.ts(53,1): error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'.
1515
Property 'length' is missing in type '{ one: number; }'.
1616
tests/cases/compiler/arrayAssignmentTest2.ts(55,1): error TS2322: Type 'C1' is not assignable to type 'any[]'.
@@ -89,11 +89,11 @@ tests/cases/compiler/arrayAssignmentTest2.ts(58,1): error TS2322: Type 'I1' is n
8989
arr_any = f1; // should be an error - is
9090
~~~~~~~
9191
!!! error TS2322: Type '() => C1' is not assignable to type 'any[]'.
92-
!!! error TS2322: Property 'push' is missing in type '() => C1'.
92+
!!! error TS2322: Property 'pop' is missing in type '() => C1'.
9393
arr_any = function () { return null;} // should be an error - is
9494
~~~~~~~
9595
!!! error TS2322: Type '() => any' is not assignable to type 'any[]'.
96-
!!! error TS2322: Property 'push' is missing in type '() => any'.
96+
!!! error TS2322: Property 'pop' is missing in type '() => any'.
9797
arr_any = o1; // should be an error - is
9898
~~~~~~~
9999
!!! error TS2322: Type '{ one: number; }' is not assignable to type 'any[]'.

tests/baselines/reference/arrayAssignmentTest4.errors.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests/cases/compiler/arrayAssignmentTest4.ts(22,1): error TS2322: Type '() => any' is not assignable to type 'any[]'.
2-
Property 'push' is missing in type '() => any'.
2+
Property 'pop' is missing in type '() => any'.
33
tests/cases/compiler/arrayAssignmentTest4.ts(23,1): error TS2322: Type 'C3' is not assignable to type 'any[]'.
44
Property 'length' is missing in type 'C3'.
55

@@ -29,7 +29,7 @@ tests/cases/compiler/arrayAssignmentTest4.ts(23,1): error TS2322: Type 'C3' is n
2929
arr_any = function () { return null;} // should be an error - is
3030
~~~~~~~
3131
!!! error TS2322: Type '() => any' is not assignable to type 'any[]'.
32-
!!! error TS2322: Property 'push' is missing in type '() => any'.
32+
!!! error TS2322: Property 'pop' is missing in type '() => any'.
3333
arr_any = c3; // should be an error - is
3434
~~~~~~~
3535
!!! error TS2322: Type 'C3' is not assignable to type 'any[]'.

tests/baselines/reference/arrayLiterals3.errors.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error
1111
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'.
1212
Property '0' is missing in type 'number[]'.
1313
tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
14-
Types of property 'push' are incompatible.
15-
Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
16-
Types of parameters 'items' and 'items' are incompatible.
17-
Type 'Number' is not assignable to type 'string | number'.
18-
Type 'Number' is not assignable to type 'number'.
19-
'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible.
14+
Types of property 'pop' are incompatible.
15+
Type '() => string | number' is not assignable to type '() => Number'.
16+
Type 'string | number' is not assignable to type 'Number'.
17+
Type 'string' is not assignable to type 'Number'.
2018

2119

2220
==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (8 errors) ====
@@ -75,10 +73,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error
7573
var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[]
7674
~~
7775
!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'.
78-
!!! error TS2322: Types of property 'push' are incompatible.
79-
!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'.
80-
!!! error TS2322: Types of parameters 'items' and 'items' are incompatible.
81-
!!! error TS2322: Type 'Number' is not assignable to type 'string | number'.
82-
!!! error TS2322: Type 'Number' is not assignable to type 'number'.
83-
!!! error TS2322: 'number' is a primitive, but 'Number' is a wrapper object. Prefer using 'number' when possible.
76+
!!! error TS2322: Types of property 'pop' are incompatible.
77+
!!! error TS2322: Type '() => string | number' is not assignable to type '() => Number'.
78+
!!! error TS2322: Type 'string | number' is not assignable to type 'Number'.
79+
!!! error TS2322: Type 'string' is not assignable to type 'Number'.
8480

tests/baselines/reference/keyofAndIndexedAccess.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible"
8888
>Shape : Shape
8989

9090
type K11 = keyof Shape[]; // "length" | "toString" | ...
91-
>K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
91+
>K11 : number | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
9292
>Shape : Shape
9393

9494
type K12 = keyof Dictionary<Shape>; // string
@@ -108,7 +108,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ...
108108
>E : E
109109

110110
type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ...
111-
>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
111+
>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight"
112112

113113
type K17 = keyof (Shape | Item); // "name"
114114
>K17 : "name"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts(10,9): error TS2322: Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'Style'.
2+
Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'StyleArray'.
3+
Types of property 'pop' are incompatible.
4+
Type '() => { foo: string; jj: number; }[][]' is not assignable to type '() => Style'.
5+
Type '{ foo: string; jj: number; }[][]' is not assignable to type 'Style'.
6+
Type '{ foo: string; jj: number; }[][]' is not assignable to type 'StyleArray'.
7+
Types of property 'pop' are incompatible.
8+
Type '() => { foo: string; jj: number; }[]' is not assignable to type '() => Style'.
9+
Type '{ foo: string; jj: number; }[]' is not assignable to type 'Style'.
10+
Type '{ foo: string; jj: number; }[]' is not assignable to type 'StyleArray'.
11+
Types of property 'pop' are incompatible.
12+
Type '() => { foo: string; jj: number; }' is not assignable to type '() => Style'.
13+
Type '{ foo: string; jj: number; }' is not assignable to type 'Style'.
14+
Object literal may only specify known properties, and 'jj' does not exist in type 'Style'.
15+
16+
17+
==== tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts (1 errors) ====
18+
type Style = StyleBase | StyleArray;
19+
interface StyleArray extends Array<Style> {}
20+
interface StyleBase {
21+
foo: string;
22+
}
23+
24+
const blah: Style = [
25+
[[{
26+
foo: 'asdf',
27+
jj: 1 // intentional error
28+
~~~~~
29+
!!! error TS2322: Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'Style'.
30+
!!! error TS2322: Type '{ foo: string; jj: number; }[][][]' is not assignable to type 'StyleArray'.
31+
!!! error TS2322: Types of property 'pop' are incompatible.
32+
!!! error TS2322: Type '() => { foo: string; jj: number; }[][]' is not assignable to type '() => Style'.
33+
!!! error TS2322: Type '{ foo: string; jj: number; }[][]' is not assignable to type 'Style'.
34+
!!! error TS2322: Type '{ foo: string; jj: number; }[][]' is not assignable to type 'StyleArray'.
35+
!!! error TS2322: Types of property 'pop' are incompatible.
36+
!!! error TS2322: Type '() => { foo: string; jj: number; }[]' is not assignable to type '() => Style'.
37+
!!! error TS2322: Type '{ foo: string; jj: number; }[]' is not assignable to type 'Style'.
38+
!!! error TS2322: Type '{ foo: string; jj: number; }[]' is not assignable to type 'StyleArray'.
39+
!!! error TS2322: Types of property 'pop' are incompatible.
40+
!!! error TS2322: Type '() => { foo: string; jj: number; }' is not assignable to type '() => Style'.
41+
!!! error TS2322: Type '{ foo: string; jj: number; }' is not assignable to type 'Style'.
42+
!!! error TS2322: Object literal may only specify known properties, and 'jj' does not exist in type 'Style'.
43+
}]]
44+
];
45+
46+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [nestedRecursiveArraysOrObjectsError01.ts]
2+
type Style = StyleBase | StyleArray;
3+
interface StyleArray extends Array<Style> {}
4+
interface StyleBase {
5+
foo: string;
6+
}
7+
8+
const blah: Style = [
9+
[[{
10+
foo: 'asdf',
11+
jj: 1 // intentional error
12+
}]]
13+
];
14+
15+
16+
17+
//// [nestedRecursiveArraysOrObjectsError01.js]
18+
var blah = [
19+
[[{
20+
foo: 'asdf',
21+
jj: 1 // intentional error
22+
}]]
23+
];
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts ===
2+
type Style = StyleBase | StyleArray;
3+
>Style : Symbol(Style, Decl(nestedRecursiveArraysOrObjectsError01.ts, 0, 0))
4+
>StyleBase : Symbol(StyleBase, Decl(nestedRecursiveArraysOrObjectsError01.ts, 1, 44))
5+
>StyleArray : Symbol(StyleArray, Decl(nestedRecursiveArraysOrObjectsError01.ts, 0, 36))
6+
7+
interface StyleArray extends Array<Style> {}
8+
>StyleArray : Symbol(StyleArray, Decl(nestedRecursiveArraysOrObjectsError01.ts, 0, 36))
9+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
10+
>Style : Symbol(Style, Decl(nestedRecursiveArraysOrObjectsError01.ts, 0, 0))
11+
12+
interface StyleBase {
13+
>StyleBase : Symbol(StyleBase, Decl(nestedRecursiveArraysOrObjectsError01.ts, 1, 44))
14+
15+
foo: string;
16+
>foo : Symbol(StyleBase.foo, Decl(nestedRecursiveArraysOrObjectsError01.ts, 2, 21))
17+
}
18+
19+
const blah: Style = [
20+
>blah : Symbol(blah, Decl(nestedRecursiveArraysOrObjectsError01.ts, 6, 5))
21+
>Style : Symbol(Style, Decl(nestedRecursiveArraysOrObjectsError01.ts, 0, 0))
22+
23+
[[{
24+
foo: 'asdf',
25+
>foo : Symbol(foo, Decl(nestedRecursiveArraysOrObjectsError01.ts, 7, 7))
26+
27+
jj: 1 // intentional error
28+
>jj : Symbol(jj, Decl(nestedRecursiveArraysOrObjectsError01.ts, 8, 20))
29+
30+
}]]
31+
];
32+
33+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/compiler/nestedRecursiveArraysOrObjectsError01.ts ===
2+
type Style = StyleBase | StyleArray;
3+
>Style : Style
4+
>StyleBase : StyleBase
5+
>StyleArray : StyleArray
6+
7+
interface StyleArray extends Array<Style> {}
8+
>StyleArray : StyleArray
9+
>Array : T[]
10+
>Style : Style
11+
12+
interface StyleBase {
13+
>StyleBase : StyleBase
14+
15+
foo: string;
16+
>foo : string
17+
}
18+
19+
const blah: Style = [
20+
>blah : Style
21+
>Style : Style
22+
>[ [[{ foo: 'asdf', jj: 1 // intentional error }]]] : { foo: string; jj: number; }[][][]
23+
24+
[[{
25+
>[[{ foo: 'asdf', jj: 1 // intentional error }]] : { foo: string; jj: number; }[][]
26+
>[{ foo: 'asdf', jj: 1 // intentional error }] : { foo: string; jj: number; }[]
27+
>{ foo: 'asdf', jj: 1 // intentional error } : { foo: string; jj: number; }
28+
29+
foo: 'asdf',
30+
>foo : string
31+
>'asdf' : "asdf"
32+
33+
jj: 1 // intentional error
34+
>jj : number
35+
>1 : 1
36+
37+
}]]
38+
];
39+
40+

0 commit comments

Comments
 (0)