-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
TypeScript Version: any
Code:
const arr: number[] | string[] = []; // Works with Array<number | string>
const arr1: number[] = [];
const arr2: string[] = [];
arr.map((a: number | string, index: number) => {
return index
})
arr.reduce((acc: Array<string>, a: number | string, index: number) => {
return []
}, [])
arr.forEach((a: number | string, index: number) => {
return index
})
arr1.map((a: number, index: number) => {
return index
})
arr1.reduce((acc: number[], a: number, index: number) => {
return [a]
}, [])
arr1.forEach((a: number, index: number) => {
return index
})
arr2.map((a: string, index: number) => {
return index
})
arr2.reduce((acc: string[], a: string, index: number) => {
return []
}, [])
arr2.forEach((a: string, index: number) => {
return index
})
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."
uqee, dadleyy, acid-chicken, aohua, robertcoopercode and 44 more
Metadata
Metadata
Assignees
Labels
Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestoneSuggestionAn idea for TypeScriptAn idea for TypeScript