You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为typescript-eslint推荐配置添加ignores规则?

解决TypeScript-ESLint扁平配置中添加ignores的错误

你的代码报错是因为Array.prototype.push()返回的是数组的新长度(数值类型),而非修改后的配置数组,导致ESLint收到的不是合法的配置对象数组,触发了TypeError: All arguments must be objects错误。

正确的配置方式

方式一:直接将ignores配置作为参数传入

把包含ignores的对象直接放到tseslint.config()的参数列表中,这是最简洁的写法:

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  { ignores: ["build/*"] }
);

方式二:先存变量再修改后导出

如果需要后续扩展配置,可以先将初始配置赋值给变量,再用push添加忽略规则,最后导出变量:

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";

const eslintConfig = tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended
);
eslintConfig.push({ ignores: ["build/*"] });

export default eslintConfig;

关键说明

ESLint扁平配置(Flat Config)要求导出的是配置对象数组,每个数组元素必须是合法的配置对象,所以必须确保最终导出的是数组类型,而非push()返回的数值。

内容的提问来源于stack exchange,提问作者Ole

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 23:21:00