ts-reset icon indicating copy to clipboard operation
ts-reset copied to clipboard

Array#includes overload doesn't work on arrays over generic types (`T[]`)

Open pavadeli opened this issue 2 years ago • 1 comments

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

pavadeli avatar Mar 09 '23 11:03 pavadeli

See #49

scottanderson avatar Mar 20 '23 18:03 scottanderson