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
And inside a recursive function, I traverse this big nested object
declareconstfields: FormStructure<TForm>return(Object.entries(fields)as[string,DefaultFieldStruture|FormStructure<TForm>][]).reduce<TReturn>((acc,[key,field])=>{if(fieldinstanceofDefaultFieldStruture){//}elseif(Array.isArray(field)&&Array.isArray(datas[key])){acc[key]=field.map((element,index)=>{// ^^^^// This expression is not callable.// Each member of the union type '(<U>(callbackfn: (value: any, index: number, array: any[]) => U, thisArg?: any) => U[]) | //(<U>(callbackfn: (value: any, index: number, array: readonly any[]) => U, thisArg?: any) => U[])' has signatures, but none // of those signatures are compatible with each other.returnmapAndCompareThroughData(element,datas[key]?.[index],predicate);}).filter((result)=>!!result);}}returnacc;},{}asTReturn);
Expected behavior:
Before passing into Array.isArray, my field var is correctly infered as
varfield: FormStructure<TForm>
After passing thought Array.isArray, it is now
varfield: FormStructure<TForm>&(FormStructure<TForm>extendsreadonlyany[] ? unknownextendsreadonlyany[]&FormStructure<TForm> ? never : readonlyany[] : any[])
I've tried puting a -readonly to my type but without success
TypeScript Version: 4.1.2
Code
I have this recursive type that I use for form generation.
And inside a recursive function, I traverse this big nested object
Expected behavior:
Before passing into
Array.isArray
, myfield
var is correctly infered asAfter passing thought
Array.isArray
, it is nowI've tried puting a
-readonly
to my type but without successIs there a way to make a type guard for this? Why Array.isArray became so strange to analyse?
Playground Link: https://www.typescriptlang.org/play?ts=4.1.0-beta#
The playground exemple doesn't works because TS 4.1-beta don't includes
isArray
new typesThe text was updated successfully, but these errors were encountered: