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

Awaiting a non-promise doesn't error #9921

Closed
tinganho opened this issue Jul 24, 2016 · 3 comments
Closed

Awaiting a non-promise doesn't error #9921

tinganho opened this issue Jul 24, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@tinganho
Copy link
Contributor

tinganho commented Jul 24, 2016

I'm kind of expecting this to throw an error:

async function test() {
    await []; // no error
}

I did a mistake of not using Promise.all():

async function test() {
    let promises: Promise<any>[] = [];
    // ...
    await Promise.all(promises); // no error
}

And it would be helpful if TS could help me catch those mistakes.

@tinganho tinganho changed the title Await a non-promise Awaiting a non-promise doesn't error Jul 24, 2016
@yortus
Copy link
Contributor

yortus commented Jul 25, 2016

I agree this is annoying as I've also occasionally put the wrong thing after await and didn't get any compiler errors.

Having said that, awaiting a non-promise is valid under the spec (although it comes under the heading 'debatable syntax'), and it has well-defined semantics. It is actually convenient in some cases (eg awaiting a value of type T|Promise<T>).

I agree it's annoying but I would not wish something that's currently valid in the ECMA proposal, and that is useful at times, to become an error in TypeScript.

If someone could think up a 'best of both worlds' approach, I'd be all for that.

@yortus
Copy link
Contributor

yortus commented Jul 25, 2016

Also, this is a duplicate of #8310, and there's a lot more discussion there.

@tinganho
Copy link
Contributor Author

Yes duplicate of #8310.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jul 25, 2016
@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

3 participants