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

TypeScript项目配eslint的prettier/recommended后无法识别override关键字怎么办

问题原因

这个prettier/prettier解析错误是因为语法解析工具无法识别TypeScript 4.3新增的override关键字,和你开启的noImplicitOverride编译校验规则无关,不需要关闭该配置。

解决方案

方案1:升级@typescript-eslint相关依赖(推荐)

你当前使用的prettier 2.4.1本身已经支持override关键字,问题大概率来自@typescript-eslint/parser和@typescript-eslint/eslint-plugin版本过低,无法正确传递TypeScript新语法到prettier。
将这两个依赖升级到4.28.0及以上版本即可,升级命令参考:

# npm
npm install @typescript-eslint/parser@^4.28.0 @typescript-eslint/eslint-plugin@^4.28.0 --save-dev

# yarn
yarn add @typescript-eslint/parser@^4.28.0 @typescript-eslint/eslint-plugin@^4.28.0 --dev

方案2:显式指定prettier解析器

如果暂时不能升级@typescript-eslint相关依赖,可以在prettier配置中强制指定用TypeScript解析器,修改你的.prettierrc如下:

{
  "singleQuote": true,
  "trailingComma": "all",
  "parser": "typescript"
}

该配置会强制prettier对所有校验文件使用TypeScript语法解析,避免自动识别解析器时出现的兼容问题。

方案3:单文件临时规避

如果上述方案都无法落地,可以在报错的文件头部添加注释,临时忽略该文件的prettier校验(不推荐,会失去该文件的格式校验能力):

/* eslint-disable prettier/prettier */

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 06:54:04