Skip to content

Commit c91d350

Browse files
authored
Update lib.es2016.array.include.d.ts
Array's `include` function checks whether or not the `searchElement` exists in it, and returns the appropriate boolean value as an answer. However, in the current implementation, TypeScript is requesting the type of `searchElement` to be a member of the array, instead of receiving any value as `searchElement`. This in turn forces the user to know in advance whether or not the `searchElement` is a member of the array, which defeats the whole purpose of using the 'include' function. The way users currently workaround that problem is by overriding the TypeScript mechanism by using "as", as suggested by @sandersn in here: microsoft#33200 (comment) . See also https://stackoverflow.com/questions/43804805/check-if-value-exists-in-enum-in-typescript . I believe that the purpose of the `include` function is to allow any variable, even if its type is unknown, to be searched in the array and get a boolean answer, and therefore I suggest the following changes. Playground: https://www.typescriptlang.org/play?#code/LAKApgdgrgtgBAMQEoFUCSAVAynA3qOOAQQAUSAZAUTgF44ByAQ3oBoC4AhIgOR6NoYAjVqAC+oUADMoEAMYAXAJYB7CHEUBnAGqMANooAmWKAAcTygE7ywBhBaiL5ACigawFtBBNR5ALjgyANYQygDuEACU-oLKyrpgjGr4IIQA9ABUEilwGAAWYHCScbphihAA5nD6EAWacPL5cBpQ5eVgGtYGcKGMAJ71yt2WgYwWyjJdjixwiZPyQxaBGtOCPt25-QaDaHC5jABuBfKDyocWFoYFGL0mYFiyFybyAPzsAOobcFtwO3uHAzMNG4rPU9vMGgVXO5PN55nVkOhsNNQrlFPEfvR4CF5s0LLV5ni9Lp+nUnLNQYx5PQNKCCii4gVvBZzG44MpJAENGVKgADMqyXRQAxgHkRV4gdiEPHyKAWNQAeUEACswAoAHT7PRQdpOBGYLARNX8wXCjQuYEwtaMGl67ARADckrg7HSqXY0tlCuVqvkGq1OttBqNchNOqhHi8PgdcFSqRyuTGoRpiTg7jGFn8RAs5VgkHm7PqNwK9CCIXC9HUNOxgK55QgjEE6OOcBMo0YMDA1gsbI58iLDED9DVOX7JYgwTCEArdWr1tr9cbR0GfduA9Q+rVXF4vCHTgATABmAAsAFYImIsrJVBoGWqSuUnJodPojKZzFYbHYHM5A2rSBRKAiaNYzgSgAA9bgUGx-HkewwFAK8IBveI72UB8nz0QxjDMSxOi-RwnHoYQgPtGM43AyDOhguCEOvW970fbRMNfHCP1sewCPoWR6BIsjQIgn1oMKPQ3FopD6LQxjnywt9cM-DjnGgXRdF4kCKMEgx-EkET4JARDkLAVD0KYl9sPfPCFKcXBRFU8iBKgzThN0NwgA
1 parent 3c8e45b commit c91d350

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/lib.es2016.array.include.d.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface Array<T> {
2424
* @param searchElement The element to search for.
2525
* @param fromIndex The position in this array at which to begin searching for searchElement.
2626
*/
27-
includes(searchElement: T, fromIndex?: number): boolean;
27+
includes(searchElement: unknown, fromIndex?: number): boolean;
2828
}
2929

3030
interface ReadonlyArray<T> {
@@ -33,7 +33,7 @@ interface ReadonlyArray<T> {
3333
* @param searchElement The element to search for.
3434
* @param fromIndex The position in this array at which to begin searching for searchElement.
3535
*/
36-
includes(searchElement: T, fromIndex?: number): boolean;
36+
includes(searchElement: unknown, fromIndex?: number): boolean;
3737
}
3838

3939
interface Int8Array {
@@ -42,7 +42,7 @@ interface Int8Array {
4242
* @param searchElement The element to search for.
4343
* @param fromIndex The position in this array at which to begin searching for searchElement.
4444
*/
45-
includes(searchElement: number, fromIndex?: number): boolean;
45+
includes(searchElement: unknown, fromIndex?: number): boolean;
4646
}
4747

4848
interface Uint8Array {
@@ -51,7 +51,7 @@ interface Uint8Array {
5151
* @param searchElement The element to search for.
5252
* @param fromIndex The position in this array at which to begin searching for searchElement.
5353
*/
54-
includes(searchElement: number, fromIndex?: number): boolean;
54+
includes(searchElement: unknown, fromIndex?: number): boolean;
5555
}
5656

5757
interface Uint8ClampedArray {
@@ -60,7 +60,7 @@ interface Uint8ClampedArray {
6060
* @param searchElement The element to search for.
6161
* @param fromIndex The position in this array at which to begin searching for searchElement.
6262
*/
63-
includes(searchElement: number, fromIndex?: number): boolean;
63+
includes(searchElement: unknown, fromIndex?: number): boolean;
6464
}
6565

6666
interface Int16Array {
@@ -69,7 +69,7 @@ interface Int16Array {
6969
* @param searchElement The element to search for.
7070
* @param fromIndex The position in this array at which to begin searching for searchElement.
7171
*/
72-
includes(searchElement: number, fromIndex?: number): boolean;
72+
includes(searchElement: unknown, fromIndex?: number): boolean;
7373
}
7474

7575
interface Uint16Array {
@@ -78,7 +78,7 @@ interface Uint16Array {
7878
* @param searchElement The element to search for.
7979
* @param fromIndex The position in this array at which to begin searching for searchElement.
8080
*/
81-
includes(searchElement: number, fromIndex?: number): boolean;
81+
includes(searchElement: unknown, fromIndex?: number): boolean;
8282
}
8383

8484
interface Int32Array {
@@ -87,7 +87,7 @@ interface Int32Array {
8787
* @param searchElement The element to search for.
8888
* @param fromIndex The position in this array at which to begin searching for searchElement.
8989
*/
90-
includes(searchElement: number, fromIndex?: number): boolean;
90+
includes(searchElement: unknown, fromIndex?: number): boolean;
9191
}
9292

9393
interface Uint32Array {
@@ -96,7 +96,7 @@ interface Uint32Array {
9696
* @param searchElement The element to search for.
9797
* @param fromIndex The position in this array at which to begin searching for searchElement.
9898
*/
99-
includes(searchElement: number, fromIndex?: number): boolean;
99+
includes(searchElement: unknown, fromIndex?: number): boolean;
100100
}
101101

102102
interface Float32Array {
@@ -105,7 +105,7 @@ interface Float32Array {
105105
* @param searchElement The element to search for.
106106
* @param fromIndex The position in this array at which to begin searching for searchElement.
107107
*/
108-
includes(searchElement: number, fromIndex?: number): boolean;
108+
includes(searchElement: unknown, fromIndex?: number): boolean;
109109
}
110110

111111
interface Float64Array {
@@ -114,5 +114,5 @@ interface Float64Array {
114114
* @param searchElement The element to search for.
115115
* @param fromIndex The position in this array at which to begin searching for searchElement.
116116
*/
117-
includes(searchElement: number, fromIndex?: number): boolean;
118-
}
117+
includes(searchElement: unknown, fromIndex?: number): boolean;
118+
}

0 commit comments

Comments
 (0)