You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interface Array<T> {
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @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;
}
The above type definition comes from microsoft/TypeScript, and this is not a true generic type, you must not pass T to the searchElement, because the searchElement could be anything.
🕗 Version & Regression Information
version: 4.2.4
💻 Code
typename='amer'|'saeed'|'ahmad';constarr=['amer','saeed'].includes(name);// here it returns this error, which is not correct//// TS2345: Argument of type '"amer" | "saeed" | "ahmad"' is not assignable to parameter of type '"amer" | "saeed"'. Type '"ahmad"' is not assignable to type '"amer" | "saeed"'.
🙁 Actual behavior
it returns a type error, told developer the type of argument in includes function must be the type of items in array.
🙂 Expected behavior
It should allow developer to insert anything in includes function.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
I saw a but in
Array.prototype.includes
type:The above type definition comes from microsoft/TypeScript, and this is not a true generic type, you must not pass
T
to thesearchElement
, because thesearchElement
could be anything.🕗 Version & Regression Information
version: 4.2.4
💻 Code
🙁 Actual behavior
it returns a type error, told developer the type of argument in
includes
function must be the type of items in array.🙂 Expected behavior
It should allow developer to insert anything in
includes
function.The text was updated successfully, but these errors were encountered: