# unicorn/no-await-expression-member

> Disallow reading a property directly from an `await` expression

`(await getUser(id)).name` needs parentheses, and they're easy to forget. Without them, `await getUser(id).name` reads `name` from the promise and gives you `undefined`. If you destructure, or put the awaited value in a variable, you don't need parentheses and the code reads from left to right.

`--fix-dangerously` rewrites `const name = (await getUser(id)).name` and `const first = (await getPosts(id))[0]` to destructuring. You need to rewrite other forms by hand.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-await-expression-member" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
async function show(id) {
  const name = (await getUser(id)).name;
  const first = (await getPosts(id))[0];
  render(name, first);
}
```

{/* bad */}
```js
async function load(url) {
  return (await fetch(url)).json();
}
```

Not reported:

{/* good */}
```js
async function show(id) {
  const { name } = await getUser(id);
  const [first] = await getPosts(id);
  render(name, first);
}
```

{/* good */}
```js
async function load(url) {
  const response = await fetch(url);
  return response.json();
}
```
