From c91d350fc927d9625f03884dbe7402d930889436 Mon Sep 17 00:00:00 2001 From: Asaf S Date: Tue, 7 Sep 2021 13:05:03 +0300 Subject: [PATCH] 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: https://github.com/microsoft/TypeScript/issues/33200#issuecomment-527670779 . 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 --- lib/lib.es2016.array.include.d.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/lib.es2016.array.include.d.ts b/lib/lib.es2016.array.include.d.ts index 6bc6ef30e7e42..d68304210b33b 100644 --- a/lib/lib.es2016.array.include.d.ts +++ b/lib/lib.es2016.array.include.d.ts @@ -24,7 +24,7 @@ interface Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: T, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface ReadonlyArray { @@ -33,7 +33,7 @@ interface ReadonlyArray { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: T, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Int8Array { @@ -42,7 +42,7 @@ interface Int8Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Uint8Array { @@ -51,7 +51,7 @@ interface Uint8Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Uint8ClampedArray { @@ -60,7 +60,7 @@ interface Uint8ClampedArray { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Int16Array { @@ -69,7 +69,7 @@ interface Int16Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Uint16Array { @@ -78,7 +78,7 @@ interface Uint16Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Int32Array { @@ -87,7 +87,7 @@ interface Int32Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Uint32Array { @@ -96,7 +96,7 @@ interface Uint32Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Float32Array { @@ -105,7 +105,7 @@ interface Float32Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; + includes(searchElement: unknown, fromIndex?: number): boolean; } interface Float64Array { @@ -114,5 +114,5 @@ interface Float64Array { * @param searchElement The element to search for. * @param fromIndex The position in this array at which to begin searching for searchElement. */ - includes(searchElement: number, fromIndex?: number): boolean; -} \ No newline at end of file + includes(searchElement: unknown, fromIndex?: number): boolean; +}