-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Can't call array methods on type (A[] | B[]) #18602
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Duplicate
An existing issue was already created
Comments
Duplicate #7294 |
Also #10620 |
It's not exactly the same but you could use a type alias to circumvent this issue: type stringOrNumber = string | number;
function test(items: stringOrNumber[]) {
items.forEach(item => console.log(item));
} |
It isn't really an issue, in that the compiler is doing what it is instructed to do, albeit it can be slightly confusing. Also a type alias is not required: function test(items: (string | number)[]) {
items.forEach(item => console.log(item));
} |
@rdeneau actually is't what I did :) |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
TypeScript Version: 2.5.2
Code
Expected behavior:
no error
Actual behavior:
The text was updated successfully, but these errors were encountered: