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#includes overload doesn't work on arrays over generic types (T[]) #111

Open
pavadeli opened this issue Mar 9, 2023 · 1 comment
Open

Comments

@pavadeli
Copy link

pavadeli commented Mar 9, 2023

While this works (no type error):

const arr: ('a' | 'b')[] = [];
arr.includes('some string');

This doesn't seem to extend to arrays that are defined in terms of a type parameter, e.g.:

function someFn<T extends string>() {
    const arr: T[] = [];
    arr.includes('some string');
    //           ^^^^^^^^^^^^^ Argument of type '"some string"' is not assignable to parameter of type 'T | (WidenLiteral<T> & {})'
}

Playground link: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAcgAIwjAhgGwLQwJ5gCmAzgMZTBgwD0Mx2UJhMCA3AFDsBmArgHakYwCHzgwAFsGIB1aAGtiAeS4BhCDyjFCACgCUcAN7s4JuKRHF4EqbKgKAXHG0J0COAB9EAIwS6A2gC6cAC8cIEcpmKSMvLEAHTAApg8ACYkzsQQIIRwlhR8AOa+HAC+nLwCQiJwYFAQXpiEIACCADwAKnCEAB4whHwpxIiuHt4IAHx6hsam5nyWUVIAIhAkfDCO7YEhYQERptbEK2swCUmp6QiZ2bkw+UW6peX8gsKitfWNIABCHV29-UGt3uk30RkicwWh2OxHWm22oXCMxM0NWsNOiVIyTSxAyWRyeUSDyeQA

@scottanderson
Copy link

See #49

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