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 of function return type has failed with overloads and tagged union types #13780

Closed
falsandtru opened this issue Jan 31, 2017 · 1 comment
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Jan 31, 2017

This problem is caused by the order of overload.

TypeScript Version: master

Code

declare function f<P, R, S>(process: Supervisor.Process<P, R, S>): void;
declare function f<P, R, S>(process: Supervisor.Process.Call<P, R, S>): void;
namespace Supervisor {
  export type Process<P, R, S> = {
    readonly init: Process.Init<S>;
    readonly call: Process.Call<P, R, S>;
    readonly exit: Process.Exit<S>;
  };
  export namespace Process {
    export type Init<S> = (state: S) => S;
    export type Call<P, R, S> = (param: P, state: S) => [R, S] | PromiseLike<[R, S]>;
    export type Exit<S> = (state: S, reason: any) => void;
  }
}
f<void, void, void>(() => [undefined, undefined]);

Expected behavior:

ok

Actual behavior:

$ node built/local/tsc.js -t es6 index.ts
index.ts(15,21): error TS2345: Argument of type '() => any[]' is not assignable to parameter of type 'Call<void, void, void>'.
  Type 'any[]' is not assignable to type '[void, void] | PromiseLike<[void, void]>'.
    Type 'any[]' is not assignable to type 'PromiseLike<[void, void]>'.
      Property 'then' is missing in type 'any[]'.

If you swap the order of the overload, this error will be resolved.

declare function f<P, R, S>(process: Supervisor.Process.Call<P, R, S>): void;
declare function f<P, R, S>(process: Supervisor.Process<P, R, S>): void;
@falsandtru falsandtru changed the title Type inference of function return type has failed with tagged union types Type inference of function return type has failed with overloads and tagged union types Jan 31, 2017
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 24, 2017
@RyanCavanaugh
Copy link
Member

Overload order does matter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

2 participants