Skip to content
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

type inference bug/limitation: union return types vs. multiple overloads. #6876

Closed
brandf opened this issue Feb 3, 2016 · 2 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@brandf
Copy link

brandf commented Feb 3, 2016

The DefinatelyTyped definitions for bluebird have an overload that looks like this:

attempt<T>(fn: () => PromiseLike<T>, args?: any[], ctx?: any): Promise<T>;
attempt<T>(fn: () => T, args?: any[], ctx?: any): Promise<T>;

If I try to call it with a function that has the following signature:

type MaybePromise<T> = () => T | Promise<T>

(note: Promise implements PromiseLike)
The type inference doesn't seem to be considering both overloads. It seems like it should, which is why I'm filing this issue.

As a temporary fix I've made a pull request to use a union type for the fn return value, but this feels like I'm working around a compiler bug.

DefinitelyTyped/DefinitelyTyped#7958

For a min-repro, see the PR above. The test cases I added fail if I don't make the non-test changes in that PR (switching to a union type).

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 3, 2016
@RyanCavanaugh
Copy link
Member

See #6735 and #1805

@brandf
Copy link
Author

brandf commented Feb 3, 2016

Thanks Ryan. Sounds like given that this is a known issue and it's the mutli-argument case it is unlikely to be supported. I will try to get the bluebird definitions updated on DefinatelyTyped.

@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

2 participants