简体   繁体   English

当 types.ts 中存在任何枚举时,为什么 eslint 会给出错误消息?

[英]Why eslint gives an error message when any enum present in types.ts?

I have a project with Vue3, Quasar, Typescript & Eslint.我有一个 Vue3、Quasar、Typescript 和 Eslint 的项目。 When I've added a enum in my types file, like this:当我在类型文件中添加枚举时,如下所示:

/* eslint-disable */
export type TableFieldType = 'default' | 'expandable' | 'editable' | 'button' | 'custom' | 'json';

export type Selection = 'select' | 'multiselect' | undefined;

export enum SortDirection {
  'asc' = 1, 'desc' = -1, 'nd' = 0
}

node started to give a very strange error:节点开始给出一个非常奇怪的错误:

[eslint] Node must be provided when reporting error if location is not provided
Occurred while linting /home/hvedrung/projects/table-component/src/types.ts:2

(the line 2 because code start from this line. If I remove comment in the line 1, error will refer to line 1. It don't like the types.ts at all) (第 2 行,因为代码从这一行开始。如果我删除第 1 行中的注释,错误将引用第 1 行。它根本不喜欢 types.ts)

If I remove enum error disappearing.如果我删除枚举错误消失。

What I've tried:我试过的:

  • added /* eslint-disable */ in types.ts在 types.ts 中添加 /* eslint-disable */
  • added "no-shadow": "off" to eslint rules在 eslint 规则中添加了 "no-shadow": "off"
  • tried to move enum in another file - in this case error contains reference to file with enum试图将枚举移动到另一个文件中 - 在这种情况下,错误包含对带有枚举的文件的引用

With no any result.没有任何结果。

Had anybody seen such error?有人见过这样的错误吗? What am I doing wrong?我究竟做错了什么?

Ok, I've solve the issue.好的,我已经解决了问题。 Just removed quotes in enum keys.刚刚删除了枚举键中的引号。 I don't know why it works so.我不知道为什么它会这样。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我收到错误“只能从对象 types.ts(2698) 创建传播类型” - Im getting an error "Spread types may only be created from object types.ts(2698)" 如何从 Types.ts 文件中导出 TypeScript 中的 object - How to export object in TypeScript from Types.ts file Typescript Output 文件“../types.ts”尚未从源文件“../types.d.ts”构建 ts(6305) - Typescript Output File '../types.ts' Has Not Been Built from Source File '../types.d.ts' ts(6305) 为什么 TS 在使用条件类型时会抛出错误? - Why TS throwing an error when using conditional types? 使用 Firebase config.ts 文件设置 Vue 3 + Quasar 时,我收到此 eslint 错误:Unsafe assignment of an `any` value - When setting up Vue 3 + Quasar with a Firebase config.ts file I get this eslint error: Unsafe assignment of an `any` value 为什么 d.ts 文件在导入不存在的变量/类型时不会抛出错误? - Why does d.ts files do not throw an error when importing inexistent variables/types? Svelte+TS+Eslint 项目,eslint 抛出错误:'console' is not defined - Svelte+TS+Eslint project, eslint throws error: 'console' is not defined 与 TS 反应,eslint 错误导入/未解决 - React with TS, eslint error import/no-unresolved component.ts 类在返回类型为 iActionResult 时出错 - component.ts class gives an error when the return type is iActionResult Eslint:解析错误:ts.createWatchCompilerHost 不是 function - Eslint: Parsing error: ts.createWatchCompilerHost is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM