Flow: Better error messages with async/await

Created on 30 Mar 2018  路  8Comments  路  Source: facebook/flow

async function f () {
  let [res] = await k()
  console.log(res.status)
}
async function k (): Promise<[?Object]> {
  return [null]
}

will get this strange error message:

let [res] = await k()
                       ^ Cannot call await with `k()` bound to `p` because an indexer property is missing in `Promise` [1].

    References:

    5: async function k (): Promise<[?Object]> {
                            ^ [1]

But if I change the function order:

async function k (): Promise<[?Object]> {
  return [null]
}
async function f () {
  let [res] = await k()
  console.log(res.status)
}

the message is ok:
`` console.log(res.status) ^ Cannot getres.statusbecause propertystatus` is missing in null or undefined [1].

References:

1: async function k (): Promise<[?Object]> {
                                 ^ [1]```
error messages

Most helpful comment

I'm getting the same problem and oddly doing await await seems to work -- but I don't think that should be right. (If you do that in your example above, it works.)

All 8 comments

I'm getting the same problem and oddly doing await await seems to work -- but I don't think that should be right. (If you do that in your example above, it works.)

I often have such error and I don't always able to find solution. It's very badly that this bug exists already long ago and developers don't try to fix it. I more and more think to look to Typescript.

@weijarz It's not. It just better fits your needs.

@TrySound ok, I really want to give chance flow. But sometimes I can鈥檛 understand how it works and why I've an error. Have you got information how then to debug flow in thouse cases when an error message not enough?

I would find the problem with binary search and rise an issue in this repo. Flow team is more active last few weeks so you will get a response and eventually a fix.

@TrySound I created an issue: https://github.com/facebook/flow/issues/7464

Same error than @weijarz, thanks @scottstraley for your temporary hack.

so what's the status with this issue? Is the suggestion that we use this "temporary hack" with await await?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Beingbook picture Beingbook  路  3Comments

mjj2000 picture mjj2000  路  3Comments

tp picture tp  路  3Comments

ctrlplusb picture ctrlplusb  路  3Comments

john-gold picture john-gold  路  3Comments