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

如何配置@typescript-eslint/quotes规则强制使用双引号?

@typescript-eslint/quotes 规则支持强制双引号配置

@typescript-eslint/quotes 完全支持强制使用双引号,只是它的配置格式和原生 ESLint 的 quotes 规则不一样,你之前踩坑是因为没找对正确的配置结构。

原生 ESLint 的 quotes 规则格式是 ["error", "double", { 选项 }],但 @typescript-eslint/quotes 的第二个参数必须是配置对象,所有规则选项(包括引号偏好)都要写在这个对象里。

正确的配置写法如下:

"@typescript-eslint/quotes": [
  "error",
  {
    "prefer": "double",
    "allowTemplateLiterals": true
  }
]

你之前遇到的两个错误原因:

  • 套用原生规则格式传三个参数时,因为 @typescript-eslint/quotes 只接受最多两个参数(级别 + 配置对象),所以报Array has too many items
  • 把 "double" 作为第二个参数时,规则要求这个位置必须是对象类型,所以报Incorrect type. Expected "object"

你之前禁用 TypeScript 规则改用原生 quotes 的方式虽然能生效,但 @typescript-eslint/quotes 是专门适配 TypeScript 语法的规则,能更好地处理 TS 特有的语法节点,更推荐用上面的正确配置来替代原生规则。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 15:21:02