Closed
Description
TypeScript Version: 3.6.3
Search Terms:
Union type functions
Code
type A = number[] | string[];
const a = <A>[1];
a.forEach(element => console.log(element)); // error
Expected behavior:
No compile error. (element
is inferred to be number | string
)
Actual behavior:
Compile error. (Parameter 'element' implicity has 'any' type.
)
Playground Link:
Related Issues:
I'm unsure whether or not it is realistic to improve this. Recently I have been working with a number of A[] | B[]
types and noticed that most array operations cannot be done on these.