-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: Playground
function example(items: Array<Function> | Array<string>) {
items.forEach(() => {
// more code
})
}
A self-contained demonstration of the problem follows...
When trying to call items.forEach
it squawks with the following error
Cannot invoke an expression whose type lacks a call signature.
It's weird because the intellisense suggests the forEach
method but just typing items.forEach()
is enough to get the compiler to complain.
Expected behavior:
I was expecting the above code to be valid so that I can perform the following code and narrow the type of item
.
items.forEach(item => {
if (typeof item === 'function') {
// item is a Function
} else if (typeof item === 'string') {
// item is a String
}
})
Actual behavior:
The compiler complains on any Array.prototype.*
method
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created