Skip to content

Commit cf4d94b

Browse files
committed
Merge pull request #8515 from Arnavion/lib-d-ts-fixes-3
`this`-related changes + new String.normalize overload
2 parents d17450d + aa87df2 commit cf4d94b

7 files changed

+49
-45
lines changed

src/lib/es2015.collection.d.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ interface Map<K, V> {
44
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void;
55
get(key: K): V | undefined;
66
has(key: K): boolean;
7-
set(key: K, value?: V): Map<K, V>;
7+
set(key: K, value?: V): this;
88
readonly size: number;
99
}
1010

@@ -20,8 +20,7 @@ interface WeakMap<K, V> {
2020
delete(key: K): boolean;
2121
get(key: K): V | undefined;
2222
has(key: K): boolean;
23-
set(key: K, value?: V): WeakMap<K, V>;
24-
23+
set(key: K, value?: V): this;
2524
}
2625

2726
interface WeakMapConstructor {
@@ -32,7 +31,7 @@ interface WeakMapConstructor {
3231
declare var WeakMap: WeakMapConstructor;
3332

3433
interface Set<T> {
35-
add(value: T): Set<T>;
34+
add(value: T): this;
3635
clear(): void;
3736
delete(value: T): boolean;
3837
forEach(callbackfn: (value: T, index: T, set: Set<T>) => void, thisArg?: any): void;
@@ -48,11 +47,10 @@ interface SetConstructor {
4847
declare var Set: SetConstructor;
4948

5049
interface WeakSet<T> {
51-
add(value: T): WeakSet<T>;
50+
add(value: T): this;
5251
clear(): void;
5352
delete(value: T): boolean;
5453
has(value: T): boolean;
55-
5654
}
5755

5856
interface WeakSetConstructor {

src/lib/es2015.core.d.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface Array<T> {
3131
* @param end index to stop filling the array at. If end is negative, it is treated as
3232
* length+end.
3333
*/
34-
fill(value: T, start?: number, end?: number): T[];
34+
fill(value: T, start?: number, end?: number): this;
3535

3636
/**
3737
* Returns the this object after copying a section of the array identified by start and end
@@ -42,7 +42,7 @@ interface Array<T> {
4242
* is treated as length+end.
4343
* @param end If not specified, length of the this object is used as its default value.
4444
*/
45-
copyWithin(target: number, start: number, end?: number): T[];
45+
copyWithin(target: number, start: number, end?: number): this;
4646
}
4747

4848
interface ArrayConstructor {
@@ -402,6 +402,14 @@ interface String {
402402
*/
403403
endsWith(searchString: string, endPosition?: number): boolean;
404404

405+
/**
406+
* Returns the String value result of normalizing the string into the normalization form
407+
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.
408+
* @param form Applicable values: "NFC", "NFD", "NFKC", or "NFKD", If not specified default
409+
* is "NFC"
410+
*/
411+
normalize(form: "NFC" | "NFD" | "NFKC" | "NFKD"): string;
412+
405413
/**
406414
* Returns the String value result of normalizing the string into the normalization form
407415
* named by form as specified in Unicode Standard Annex #15, Unicode Normalization Forms.

src/lib/es5.d.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ interface Array<T> {
11391139
* Sorts an array.
11401140
* @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
11411141
*/
1142-
sort(compareFn?: (a: T, b: T) => number): T[];
1142+
sort(compareFn?: (a: T, b: T) => number): this;
11431143
/**
11441144
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
11451145
* @param start The zero-based location in the array from which to start removing elements.
@@ -1481,7 +1481,7 @@ interface Int8Array {
14811481
* is treated as length+end.
14821482
* @param end If not specified, length of the this object is used as its default value.
14831483
*/
1484-
copyWithin(target: number, start: number, end?: number): Int8Array;
1484+
copyWithin(target: number, start: number, end?: number): this;
14851485

14861486
/**
14871487
* Determines whether all the members of an array satisfy the specified test.
@@ -1501,7 +1501,7 @@ interface Int8Array {
15011501
* @param end index to stop filling the array at. If end is negative, it is treated as
15021502
* length+end.
15031503
*/
1504-
fill(value: number, start?: number, end?: number): Int8Array;
1504+
fill(value: number, start?: number, end?: number): this;
15051505

15061506
/**
15071507
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -1670,7 +1670,7 @@ interface Int8Array {
16701670
* @param compareFn The name of the function used to determine the order of the elements. If
16711671
* omitted, the elements are sorted in ascending, ASCII character order.
16721672
*/
1673-
sort(compareFn?: (a: number, b: number) => number): Int8Array;
1673+
sort(compareFn?: (a: number, b: number) => number): this;
16741674

16751675
/**
16761676
* Gets a new Int8Array view of the ArrayBuffer store for this array, referencing the elements
@@ -1754,7 +1754,7 @@ interface Uint8Array {
17541754
* is treated as length+end.
17551755
* @param end If not specified, length of the this object is used as its default value.
17561756
*/
1757-
copyWithin(target: number, start: number, end?: number): Uint8Array;
1757+
copyWithin(target: number, start: number, end?: number): this;
17581758

17591759
/**
17601760
* Determines whether all the members of an array satisfy the specified test.
@@ -1774,7 +1774,7 @@ interface Uint8Array {
17741774
* @param end index to stop filling the array at. If end is negative, it is treated as
17751775
* length+end.
17761776
*/
1777-
fill(value: number, start?: number, end?: number): Uint8Array;
1777+
fill(value: number, start?: number, end?: number): this;
17781778

17791779
/**
17801780
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -1943,7 +1943,7 @@ interface Uint8Array {
19431943
* @param compareFn The name of the function used to determine the order of the elements. If
19441944
* omitted, the elements are sorted in ascending, ASCII character order.
19451945
*/
1946-
sort(compareFn?: (a: number, b: number) => number): Uint8Array;
1946+
sort(compareFn?: (a: number, b: number) => number): this;
19471947

19481948
/**
19491949
* Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements
@@ -2028,7 +2028,7 @@ interface Uint8ClampedArray {
20282028
* is treated as length+end.
20292029
* @param end If not specified, length of the this object is used as its default value.
20302030
*/
2031-
copyWithin(target: number, start: number, end?: number): Uint8ClampedArray;
2031+
copyWithin(target: number, start: number, end?: number): this;
20322032

20332033
/**
20342034
* Determines whether all the members of an array satisfy the specified test.
@@ -2048,7 +2048,7 @@ interface Uint8ClampedArray {
20482048
* @param end index to stop filling the array at. If end is negative, it is treated as
20492049
* length+end.
20502050
*/
2051-
fill(value: number, start?: number, end?: number): Uint8ClampedArray;
2051+
fill(value: number, start?: number, end?: number): this;
20522052

20532053
/**
20542054
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -2217,7 +2217,7 @@ interface Uint8ClampedArray {
22172217
* @param compareFn The name of the function used to determine the order of the elements. If
22182218
* omitted, the elements are sorted in ascending, ASCII character order.
22192219
*/
2220-
sort(compareFn?: (a: number, b: number) => number): Uint8ClampedArray;
2220+
sort(compareFn?: (a: number, b: number) => number): this;
22212221

22222222
/**
22232223
* Gets a new Uint8ClampedArray view of the ArrayBuffer store for this array, referencing the elements
@@ -2301,7 +2301,7 @@ interface Int16Array {
23012301
* is treated as length+end.
23022302
* @param end If not specified, length of the this object is used as its default value.
23032303
*/
2304-
copyWithin(target: number, start: number, end?: number): Int16Array;
2304+
copyWithin(target: number, start: number, end?: number): this;
23052305

23062306
/**
23072307
* Determines whether all the members of an array satisfy the specified test.
@@ -2321,7 +2321,7 @@ interface Int16Array {
23212321
* @param end index to stop filling the array at. If end is negative, it is treated as
23222322
* length+end.
23232323
*/
2324-
fill(value: number, start?: number, end?: number): Int16Array;
2324+
fill(value: number, start?: number, end?: number): this;
23252325

23262326
/**
23272327
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -2490,7 +2490,7 @@ interface Int16Array {
24902490
* @param compareFn The name of the function used to determine the order of the elements. If
24912491
* omitted, the elements are sorted in ascending, ASCII character order.
24922492
*/
2493-
sort(compareFn?: (a: number, b: number) => number): Int16Array;
2493+
sort(compareFn?: (a: number, b: number) => number): this;
24942494

24952495
/**
24962496
* Gets a new Int16Array view of the ArrayBuffer store for this array, referencing the elements
@@ -2575,7 +2575,7 @@ interface Uint16Array {
25752575
* is treated as length+end.
25762576
* @param end If not specified, length of the this object is used as its default value.
25772577
*/
2578-
copyWithin(target: number, start: number, end?: number): Uint16Array;
2578+
copyWithin(target: number, start: number, end?: number): this;
25792579

25802580
/**
25812581
* Determines whether all the members of an array satisfy the specified test.
@@ -2595,7 +2595,7 @@ interface Uint16Array {
25952595
* @param end index to stop filling the array at. If end is negative, it is treated as
25962596
* length+end.
25972597
*/
2598-
fill(value: number, start?: number, end?: number): Uint16Array;
2598+
fill(value: number, start?: number, end?: number): this;
25992599

26002600
/**
26012601
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -2764,7 +2764,7 @@ interface Uint16Array {
27642764
* @param compareFn The name of the function used to determine the order of the elements. If
27652765
* omitted, the elements are sorted in ascending, ASCII character order.
27662766
*/
2767-
sort(compareFn?: (a: number, b: number) => number): Uint16Array;
2767+
sort(compareFn?: (a: number, b: number) => number): this;
27682768

27692769
/**
27702770
* Gets a new Uint16Array view of the ArrayBuffer store for this array, referencing the elements
@@ -2848,7 +2848,7 @@ interface Int32Array {
28482848
* is treated as length+end.
28492849
* @param end If not specified, length of the this object is used as its default value.
28502850
*/
2851-
copyWithin(target: number, start: number, end?: number): Int32Array;
2851+
copyWithin(target: number, start: number, end?: number): this;
28522852

28532853
/**
28542854
* Determines whether all the members of an array satisfy the specified test.
@@ -2868,7 +2868,7 @@ interface Int32Array {
28682868
* @param end index to stop filling the array at. If end is negative, it is treated as
28692869
* length+end.
28702870
*/
2871-
fill(value: number, start?: number, end?: number): Int32Array;
2871+
fill(value: number, start?: number, end?: number): this;
28722872

28732873
/**
28742874
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -3037,7 +3037,7 @@ interface Int32Array {
30373037
* @param compareFn The name of the function used to determine the order of the elements. If
30383038
* omitted, the elements are sorted in ascending, ASCII character order.
30393039
*/
3040-
sort(compareFn?: (a: number, b: number) => number): Int32Array;
3040+
sort(compareFn?: (a: number, b: number) => number): this;
30413041

30423042
/**
30433043
* Gets a new Int32Array view of the ArrayBuffer store for this array, referencing the elements
@@ -3121,7 +3121,7 @@ interface Uint32Array {
31213121
* is treated as length+end.
31223122
* @param end If not specified, length of the this object is used as its default value.
31233123
*/
3124-
copyWithin(target: number, start: number, end?: number): Uint32Array;
3124+
copyWithin(target: number, start: number, end?: number): this;
31253125

31263126
/**
31273127
* Determines whether all the members of an array satisfy the specified test.
@@ -3141,7 +3141,7 @@ interface Uint32Array {
31413141
* @param end index to stop filling the array at. If end is negative, it is treated as
31423142
* length+end.
31433143
*/
3144-
fill(value: number, start?: number, end?: number): Uint32Array;
3144+
fill(value: number, start?: number, end?: number): this;
31453145

31463146
/**
31473147
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -3310,7 +3310,7 @@ interface Uint32Array {
33103310
* @param compareFn The name of the function used to determine the order of the elements. If
33113311
* omitted, the elements are sorted in ascending, ASCII character order.
33123312
*/
3313-
sort(compareFn?: (a: number, b: number) => number): Uint32Array;
3313+
sort(compareFn?: (a: number, b: number) => number): this;
33143314

33153315
/**
33163316
* Gets a new Uint32Array view of the ArrayBuffer store for this array, referencing the elements
@@ -3394,7 +3394,7 @@ interface Float32Array {
33943394
* is treated as length+end.
33953395
* @param end If not specified, length of the this object is used as its default value.
33963396
*/
3397-
copyWithin(target: number, start: number, end?: number): Float32Array;
3397+
copyWithin(target: number, start: number, end?: number): this;
33983398

33993399
/**
34003400
* Determines whether all the members of an array satisfy the specified test.
@@ -3414,7 +3414,7 @@ interface Float32Array {
34143414
* @param end index to stop filling the array at. If end is negative, it is treated as
34153415
* length+end.
34163416
*/
3417-
fill(value: number, start?: number, end?: number): Float32Array;
3417+
fill(value: number, start?: number, end?: number): this;
34183418

34193419
/**
34203420
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -3583,7 +3583,7 @@ interface Float32Array {
35833583
* @param compareFn The name of the function used to determine the order of the elements. If
35843584
* omitted, the elements are sorted in ascending, ASCII character order.
35853585
*/
3586-
sort(compareFn?: (a: number, b: number) => number): Float32Array;
3586+
sort(compareFn?: (a: number, b: number) => number): this;
35873587

35883588
/**
35893589
* Gets a new Float32Array view of the ArrayBuffer store for this array, referencing the elements
@@ -3668,7 +3668,7 @@ interface Float64Array {
36683668
* is treated as length+end.
36693669
* @param end If not specified, length of the this object is used as its default value.
36703670
*/
3671-
copyWithin(target: number, start: number, end?: number): Float64Array;
3671+
copyWithin(target: number, start: number, end?: number): this;
36723672

36733673
/**
36743674
* Determines whether all the members of an array satisfy the specified test.
@@ -3688,7 +3688,7 @@ interface Float64Array {
36883688
* @param end index to stop filling the array at. If end is negative, it is treated as
36893689
* length+end.
36903690
*/
3691-
fill(value: number, start?: number, end?: number): Float64Array;
3691+
fill(value: number, start?: number, end?: number): this;
36923692

36933693
/**
36943694
* Returns the elements of an array that meet the condition specified in a callback function.
@@ -3857,7 +3857,7 @@ interface Float64Array {
38573857
* @param compareFn The name of the function used to determine the order of the elements. If
38583858
* omitted, the elements are sorted in ascending, ASCII character order.
38593859
*/
3860-
sort(compareFn?: (a: number, b: number) => number): Float64Array;
3860+
sort(compareFn?: (a: number, b: number) => number): this;
38613861

38623862
/**
38633863
* Gets a new Float64Array view of the ArrayBuffer store for this array, referencing the elements

tests/baselines/reference/implementArrayInterface.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare class MyArray<T> implements Array<T> {
1010
reverse(): T[];
1111
shift(): T;
1212
slice(start?: number, end?: number): T[];
13-
sort(compareFn?: (a: T, b: T) => number): T[];
13+
sort(compareFn?: (a: T, b: T) => number): this;
1414
splice(start: number): T[];
1515
splice(start: number, deleteCount: number, ...items: T[]): T[];
1616
unshift(...items: T[]): number;

tests/baselines/reference/implementArrayInterface.symbols

+3-4
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,21 @@ declare class MyArray<T> implements Array<T> {
5252
>end : Symbol(end, Decl(implementArrayInterface.ts, 10, 25))
5353
>T : Symbol(T, Decl(implementArrayInterface.ts, 0, 22))
5454

55-
sort(compareFn?: (a: T, b: T) => number): T[];
55+
sort(compareFn?: (a: T, b: T) => number): this;
5656
>sort : Symbol(MyArray.sort, Decl(implementArrayInterface.ts, 10, 45))
5757
>compareFn : Symbol(compareFn, Decl(implementArrayInterface.ts, 11, 9))
5858
>a : Symbol(a, Decl(implementArrayInterface.ts, 11, 22))
5959
>T : Symbol(T, Decl(implementArrayInterface.ts, 0, 22))
6060
>b : Symbol(b, Decl(implementArrayInterface.ts, 11, 27))
61-
>T : Symbol(T, Decl(implementArrayInterface.ts, 0, 22))
6261
>T : Symbol(T, Decl(implementArrayInterface.ts, 0, 22))
6362

6463
splice(start: number): T[];
65-
>splice : Symbol(MyArray.splice, Decl(implementArrayInterface.ts, 11, 50), Decl(implementArrayInterface.ts, 12, 31))
64+
>splice : Symbol(MyArray.splice, Decl(implementArrayInterface.ts, 11, 51), Decl(implementArrayInterface.ts, 12, 31))
6665
>start : Symbol(start, Decl(implementArrayInterface.ts, 12, 11))
6766
>T : Symbol(T, Decl(implementArrayInterface.ts, 0, 22))
6867

6968
splice(start: number, deleteCount: number, ...items: T[]): T[];
70-
>splice : Symbol(MyArray.splice, Decl(implementArrayInterface.ts, 11, 50), Decl(implementArrayInterface.ts, 12, 31))
69+
>splice : Symbol(MyArray.splice, Decl(implementArrayInterface.ts, 11, 51), Decl(implementArrayInterface.ts, 12, 31))
7170
>start : Symbol(start, Decl(implementArrayInterface.ts, 13, 11))
7271
>deleteCount : Symbol(deleteCount, Decl(implementArrayInterface.ts, 13, 25))
7372
>items : Symbol(items, Decl(implementArrayInterface.ts, 13, 46))

tests/baselines/reference/implementArrayInterface.types

+2-3
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ declare class MyArray<T> implements Array<T> {
5252
>end : number
5353
>T : T
5454

55-
sort(compareFn?: (a: T, b: T) => number): T[];
56-
>sort : (compareFn?: (a: T, b: T) => number) => T[]
55+
sort(compareFn?: (a: T, b: T) => number): this;
56+
>sort : (compareFn?: (a: T, b: T) => number) => this
5757
>compareFn : (a: T, b: T) => number
5858
>a : T
5959
>T : T
6060
>b : T
61-
>T : T
6261
>T : T
6362

6463
splice(start: number): T[];

tests/cases/compiler/implementArrayInterface.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare class MyArray<T> implements Array<T> {
99
reverse(): T[];
1010
shift(): T;
1111
slice(start?: number, end?: number): T[];
12-
sort(compareFn?: (a: T, b: T) => number): T[];
12+
sort(compareFn?: (a: T, b: T) => number): this;
1313
splice(start: number): T[];
1414
splice(start: number, deleteCount: number, ...items: T[]): T[];
1515
unshift(...items: T[]): number;

0 commit comments

Comments
 (0)