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

Error inferring tuple type arguments #16360

Open
ghost opened this issue Jun 8, 2017 · 2 comments
Open

Error inferring tuple type arguments #16360

ghost opened this issue Jun 8, 2017 · 2 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@ghost
Copy link

ghost commented Jun 8, 2017

TypeScript Version: nightly (2.4.0-dev.20170608)

Code

interface IPromise<T> {
    then<U>(onFulfill: (value: T) => IWhenable<U>): IPromise<U>;
}

interface QPromise<T> {
    then<U>(onFulfill: (value: T) => IWhenable<U>): IPromise<U>;
}

type IWhenable<T> = IPromise<T> | T;

declare function all<A, B>(promises: IWhenable<[IWhenable<A>, IWhenable<B>]>): IPromise<[A, B]>;

declare const prom1: QPromise<[QPromise<string>, QPromise<number>]>;
const x1: IPromise<[string, number]> = all(prom1);

const prom2: IPromise<[IPromise<string>, IPromise<number>]> = prom1;
const x2: IPromise<[string, number]> = all(prom2);

Expected behavior:

Since IPromise and QPromise have identical bodies, I would expect these to both work.

Actual behavior:

x1 fails, x2 succeeds.

src/a.ts(14,7): error TS2322: Type 'IPromise<[QPromise<string>, QPromise<number>]>' is not assignable to type 'IPromise<[string, number]>'.
  Type '[QPromise<string>, QPromise<number>]' is not assignable to type '[string, number]'.
    Type 'QPromise<string>' is not assignable to type 'string'.
@mhegazy
Copy link
Contributor

mhegazy commented Feb 12, 2018

Seems like a duplicate of #19194

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 12, 2018
@ghost
Copy link
Author

ghost commented Feb 12, 2018

@mhegazy I don't think this is a duplicate -- that issue references the actual Promise definitions from lib, but this is a type inference issue that just happens to use a promise-like type as an example. Here's a simpler repro:

interface IPromise<T> {
    then(onFulfill: (value: T) => void): void;
}
interface QPromise<T> {
    then(onFulfill: (value: T) => void): void;
}
type IWhenable<T> = IPromise<T> | T;

declare function unwrapTwice<T>(p: IWhenable<IWhenable<T>>): T;
declare const qq: QPromise<QPromise<string>>;
const x: string = unwrapTwice(qq); // Error: unwraps once...

@mhegazy mhegazy added Bug A bug in TypeScript and removed Duplicate An existing issue was already created labels Feb 12, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Apr 12, 2018
@mhegazy mhegazy modified the milestones: TypeScript 3.0, Future Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants