首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >禁用单行的“noImpl时任意”TS规则

禁用单行的“noImpl时任意”TS规则
EN

Stack Overflow用户
提问于 2021-11-15 06:49:12
回答 1查看 1.9K关注 0票数 1

我已经在tsconfig.json中启用了TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}',并在代码空间中得到了TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'错误。

我想对单行禁用这个规则,我尝试了下面的代码,但是它没有工作。

代码语言:javascript
运行
复制
const mockElement = () => ({
  mount: jest.fn(),
  destroy: jest.fn(),
  on: jest.fn(),
  update: jest.fn(),
});

const mockElements = () => {
  const elements = {};
  return {
    create: jest.fn((type) => {
      // getting error from the bellow line
      // tslint:disable-next-line: no-implicit-any
      elements[type] = mockElement();
      // getting error from the bellow line
      // tslint:disable-next-line: no-implicit-any
      return elements[type];
    }),
    getElement: jest.fn((type) => {
      // getting error from the bellow line
      // tslint:disable-next-line: no-implicit-any
      return elements[type] || null;
    }),
  };
};

对于仅对一行禁用规则有任何建议吗?(在"noImplicitAny": false中设置tsconfig.json可以工作,但不能接受,因为它完全禁用了规则)

EN

回答 1

Stack Overflow用户

发布于 2022-07-04 18:37:09

这是一个ESLint的问题,而不是一个类型记录编译器的事情。在你的来源里试试这个

// eslint-disable-next-line @typescript-eslint/no-explicit-any

因此,这是针对EXplicit any的,但是我认为您可以通过在您需要的一行上显式地定义它来解决这个问题?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69970363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档