mk-toolブログ

エンジニアと家のことをごちゃごちゃと書いてます

Use object destructuring prefer-destructuring

以下のような場合、eslintがエラーが報告してくる。

async post(req: Request, res: Response) {
  const body = req.body;
}

そのため、以下のように修正することでエラーがなくなる。 プロパティをドット区切りで取得するのではなく、変数を展開して格納してあげる。

async post(req: Request, res: Response) {
  const { body } = req;
}