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
Code
There seems to be an error in type of indexOf function in Array interface. It seems to be too strict, not allowing to search for values that might or might not be inside the array.
typeAB='A'|'B';typeCD='C'|'D';typeABCD=AB|CD;constfn1=(t: AB[],v: ABCD)=>t.indexOf(v);// v might be "B" so it is a perfectly valid indexOf usageconstfn2=(t: AB[],v: CD)=>t.indexOf(v);// AB and CD have nothing in common, this might be an errorconstfn3=(t: ABCD[],v: AB)=>t.indexOf(v);// this is ok
Expected behavior: indexOf inside fn1 shouldn't throw an error because there is a non-empty intersection between array values type and searched value type
Actual behavior: indexOf inside fn1 throws the following error:
Argument of type 'ABCD' is not assignable to parameter of type 'AB'.
Type '"C"' is not assignable to type 'AB'.ts(2345)
TypeScript Version: 3.4.0 and 3.5.0-dev.20190418
Search Terms: indexOf, array union, ts(2345)
Code
There seems to be an error in type of
indexOf
function inArray
interface. It seems to be too strict, not allowing to search for values that might or might not be inside the array.Expected behavior:
indexOf
insidefn1
shouldn't throw an error because there is a non-empty intersection between array values type and searched value typeActual behavior:
indexOf
insidefn1
throws the following error:Playground Link: TypeScript Playground
The text was updated successfully, but these errors were encountered: