Closed
Description
π Search Terms
array.includes, types
π Version & Regression Information
- This is the behavior in every version I tried - the type definition is 7 years old.
β― Playground Link
π» Code
No response
π Actual behavior
I should not receive type errors because an argument of type string | null
might be included in an array of type string[]
. It is the job of the method to make the final determination.
π Expected behavior
I get type errors because Array<string>.includes()
will only accept a string value. I have to cast my argument to a string in order to perform the check.
Additional information about the issue
Basic suggested change:
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;
+ includes<U extends T>(searchElement: U, fromIndex?: number): boolean;}
interface ReadonlyArray<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;
+ includes<U extends T>(searchElement: U, fromIndex?: number): boolean;}
// ...
}