TypeScript Version: any
Code:
constarr: number[]|string[]=[];// Works with Array<number | string>constarr1: number[]=[];constarr2: string[]=[];arr.map((a: number|string,index: number)=>{returnindex})arr.reduce((acc: Array<string>,a: number|string,index: number)=>{return[]},[])arr.forEach((a: number|string,index: number)=>{returnindex})arr1.map((a: number,index: number)=>{returnindex})arr1.reduce((acc: number[],a: number,index: number)=>{return[a]},[])arr1.forEach((a: number,index: number)=>{returnindex})arr2.map((a: string,index: number)=>{returnindex})arr2.reduce((acc: string[],a: string,index: number)=>{return[]},[])arr2.forEach((a: string,index: number)=>{returnindex})Expected behavior: TS should let me iterate through array (I tell it the type is either array of numbers OR array of strings (not an array of mixed types). In any case the variable is an array and those methods should be callable.
Actual behavior: TS throws error "This expression is not callable."
TypeScript Version: any
Code:
Expected behavior: TS should let me iterate through array (I tell it the type is either array of numbers OR array of strings (not an array of mixed types). In any case the variable is an array and those methods should be callable.
Actual behavior: TS throws error "This expression is not callable."