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

Regression: TypeScript no longer awaits custom Promises #8423

Closed
RReverser opened this issue May 2, 2016 · 12 comments
Closed

Regression: TypeScript no longer awaits custom Promises #8423

RReverser opened this issue May 2, 2016 · 12 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@RReverser
Copy link
Contributor

TypeScript Version:

1.9.0-dev.20160502

Code

declare namespace Windows.Foundation {
    interface IPromise<TResult> {
        then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
        then<U>(success?: (value: TResult) => IPromise<U>, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
        then<U>(success?: (value: TResult) => U, error?: (error: any) => IPromise<U>, progress?: (progress: any) => void): IPromise<U>;
        then<U>(success?: (value: TResult) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise<U>;
        done<U>(success?: (value: TResult) => any, error?: (error: any) => any, progress?: (progress: any) => void): void;

        cancel(): void;
    }
}

async function sample(promise: Windows.Foundation.IPromise<number>) {
    var number = await promise;
}

Expected behavior:
No error, as this is an await-compatible Promise definition; more concretely, those are definitions for UWP APIs and they worked well with a stable TypeScript.

Actual behavior:
Compiler emits an error Operand for 'await' does not have a valid callable 'then' member..

@RReverser RReverser changed the title Regression: TypeScript no longer await custom Promises Regression: TypeScript no longer awaits custom Promises May 2, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 2, 2016

Please see #6068 for more details.

@mhegazy mhegazy added the Duplicate An existing issue was already created label May 2, 2016
@RReverser
Copy link
Contributor Author

RReverser commented May 2, 2016

@mhegazy Doesn't look like a duplicate - that issue seems to be describing setting global Promise to another value, while this one is about awaiting a custom implementation that exists under a custom name, while does fulfill thenable interface.

@mhegazy mhegazy removed the Duplicate An existing issue was already created label May 2, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 2, 2016

sorry about that. indeed the wrong reference.

@mhegazy
Copy link
Contributor

mhegazy commented May 2, 2016

but i do not get an error for this locally. looks like there is something else going on.. can you share more code?

@RReverser
Copy link
Contributor Author

RReverser commented May 2, 2016

Well, I limited to this minimal example and I'm certainly seeing this error. Perhaps something in the config, let me try without one.

@RReverser
Copy link
Contributor Author

RReverser commented May 2, 2016

Okay, this seems to be happening only when strictNullChecks is enabled. Although I don't really see the connection yet.

@RReverser
Copy link
Contributor Author

@mhegazy Please let me know if any other details are needed for this bug.

@vladima
Copy link
Contributor

vladima commented May 3, 2016

I can repro this.

@vladima vladima added the Bug A bug in TypeScript label May 3, 2016
@Arnavion
Copy link
Contributor

Arnavion commented May 3, 2016

While you're at it, could you also make that error list exactly how the then is not the expected signature in the general case? For example could you print out the types for both and how they disagree (just like the error for mismatching types in general does)?

mhegazy added a commit that referenced this issue May 3, 2016
@mhegazy mhegazy self-assigned this May 3, 2016
@mhegazy mhegazy added this to the TypeScript 2.0 milestone May 3, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 3, 2016
@RReverser
Copy link
Contributor Author

@mhegazy Thank you! Fast as always, it's a pleasure to be beta-tester :)

@mhegazy
Copy link
Contributor

mhegazy commented May 3, 2016

While you're at it, could you also make that error list exactly how the then is not the expected signature in the general case? For example could you print out the types for both and how they disagree (just like the error for mismatching types in general does)?

For this specific check, it actually passed. First we try to get the promised type from the then signatures if that failed, we want to make sure the type does not have a then property on it, or it might be used, and you can get an unexpected behavior at runtime. so we compare it to something that has a then in this case it passes.

the issue was a bit earlier than this specif check, during getting the promised type; now that undefined is added to optional arguments by default, we try to get the signature of a union type of first arg in all overloads and it fails as undefined does not have any signatures.

@mhegazy
Copy link
Contributor

mhegazy commented May 3, 2016

Thanks @RReverser! we do appreciate you feedback, keep the reports coming.

mhegazy added a commit that referenced this issue May 4, 2016
Fix #8423: Remove undefined while getting the type of the first argument of then signature
@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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants