我已经在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 '{}'
错误。
我想对单行禁用这个规则,我尝试了下面的代码,但是它没有工作。
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可以工作,但不能接受,因为它完全禁用了规则)
发布于 2022-07-04 18:37:09
这是一个ESLint的问题,而不是一个类型记录编译器的事情。在你的来源里试试这个
// eslint-disable-next-line @typescript-eslint/no-explicit-any
因此,这是针对EXplicit any的,但是我认为您可以通过在您需要的一行上显式地定义它来解决这个问题?
https://stackoverflow.com/questions/69970363
复制相似问题