Skip to content

"cannot invoke an expression whose type lacks a call signature" on union of types both having this call signature #11223

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

Closed
fabiospampinato opened this issue Sep 28, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@fabiospampinato
Copy link

TypeScript Version: 2.0.3

Code

function foo ( arg: number[] | string[] ) {
    arg.find ( () => false ); // cannot invoke an expression whose type lacks a call signature
} 

function bar ( arg: (number | string)[] ) {
    arg.find ( () => false );
}

Expected behavior:

Inside foo, arg is always an array, either of numbers or of strings, so I expect the find method to be recognized by the compiler.

Actual behavior:

It doesn't recognize it, and it throws a cannot invoke an expression whose type lacks a call signature error.

I don't see any good reason why inside bar the compiler understands that arg is always an array, but not inside foo.

@kitsonk
Copy link
Contributor

kitsonk commented Sep 28, 2016

Dupe of #10620 (second one today, after #11205)

@fabiospampinato
Copy link
Author

Sorry about that. I didn't find them on my searches.

@mhegazy mhegazy added the Duplicate An existing issue was already created label Sep 29, 2016
@mhegazy mhegazy closed this as completed Sep 29, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants