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
/**
* function illustrates typescript compile error. Generic function recursively
* calls itself. Get error TS2345 on statement where function calls itself.
* This code compiles without error using typescript version 4.0.5 or lower.
* The compile fails at typescript version 4.1.2
* @param arr1
* @param arr2
*/
export function genericArrayProblem<T>(arr1: T[], arr2: T[]): boolean
{
for( let ix = 0 ; ix < arr1.length ; ++ix )
{
if ( ix < arr2.length )
{
const item1 = arr1[ix];
const item2 = arr2[ix];
if (Array.isArray(item1) && Array.isArray(item2))
{
const res = genericArrayProblem(item1, item2);
}
}
}
return true ;
}
Expected behavior:
Expecting code to compile. It compiles successfully using typescript version 4.0.5 or lower.
Actual behavior:
get compile error:
error TS2345: Argument of type 'T & (T extends readonly any[] ? unknown extends T
? never : readonly any[] : any[])' is not assignable to parameter of type 'any[]'.
const res = genericArrayProblem(item1, item2);
Activity
RyanCavanaugh commentedon Dec 3, 2020
Evaluating
isArraybreaks at #41808