Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.prototype.includes type definition issue #48819

Closed
amerllica opened this issue Apr 23, 2022 · 2 comments
Closed

Array.prototype.includes type definition issue #48819

amerllica opened this issue Apr 23, 2022 · 2 comments

Comments

@amerllica
Copy link

amerllica commented Apr 23, 2022

Bug Report

🔎 Search Terms

I saw a but in Array.prototype.includes type:

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

type name = 'amer' | 'saeed' | 'ahmad';
const arr = ['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.

@jcalz
Copy link
Contributor

jcalz commented Apr 23, 2022

Duplicate #48247 and others.

You forgot to fill out the “search terms” part of the template showing how you searched for existing issues before filing a new issue.

@amerllica
Copy link
Author

I just closed this issue because of duplicated #48247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants