-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
better type coercion : instead of cannot invoke an expression whose type lacks a call signature #20877
Comments
This might be fixed by #17819; @weswigham? |
Thanks @DanielRosenwasser for your interest. As far as I can tell of your example, the union type is for signatures with same return type and but differing parameter types. In my case, the parameter is of one type only. The return type changes depending of what happen at rutime: the callback in the So, no sure this might be a fix. However, I was able to increase typing complexity, wrote a solution that worked, then striped off unnecessary code until I got a simple solution that works just as I expected (even the implementation is now tiny). export interface HopeLike<T, S = void>
{
<U>(map: (value: T) => U, asHoped?: (value: U) => boolean): HopeLike<U, T>;
or(map: (parent: S) => T): HopeLike<T, S>;
get(): T | void;
} You may discover that the redesigned interface express something strongly different from the first version. I figured out that I wrongly implemented the solution to that my specific problem. Nonetheless, the question remains: [W]hy TypeScript cannot (yet) infer that union type of two functions is a function, thus callable? Therefore, I call for possible duplicates as I believe this isn't the first issue opened about... |
I have reduced the problem down so it is easier to to see the issue:
|
You got it clear, @sylvanaar |
Duplicate of #7294 |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.6.2
Code
Note that this code works well if
.or
call is not called twice!A concrete usecase
Where :
const EVENT_EMMITTERS: WeakMap<EventEmitter<any>, Map<string, EventHandlerLike<any>[]>> = new WeakMap();
this
context is instance ofEventEmitter
Expected behavior:
I had expected these to be inferred after the
.or
second call:p
asnumber | string
HopeLike<number, number> | HopeLike<U, number> | HopeLike<string, number> | HopeLike<U, string>
Actual behavior:
The error says
cannot invoke an expression whose type lacks a call signature. Type '(<U>(callable: (parent: number, value: number) => U): HopeLike<number, number> | HopeLike<U, nu...'
The text was updated successfully, but these errors were encountered: