初めに
buildの実行で発生したエラーを解決できたので、共有します。
問題
res.status(500).json({ error.error });
で以下エラーが発生しました。
Expected property shorthand.eslint(object-shorthand)
import { NextApiRequest, NextApiResponse } from 'next';
import { todoData } from '@/data/todoData';
const handler = (req: NextApiRequest, res: NextApiResponse) => {
try {
res.status(200).json(todoData);
} catch (error) {
res.status(500).json({ error.error });
}
};
export default handler;
原因
ESLintのルールであるobject-shorthand
がプロパティのショートハンド記法の使用を期待しているからです。このルールは、オブジェクトリテラル内で変数名とプロパティ名が同じ場合に、ショートハンド記法を使うことを推奨しています。
解決方法
エラーも消えて、記述量も減りました。
res.status(500).json({ error });
終わりに
ESLintのルールを知れたので、学びになりました。