Cypress文档展示了如何声明自定义命令类型:
declare global {
namespace Cypress {
interface Chainable {
/**
* Custom command to select DOM element by data-cy attribute.
* @example cy.dataCy('greeting')
*/
dataCy(value: string): Chainable<Element>
}
}
}
但是TypeScript ESLint对此感到不满,原因是“ES2015模块语法优于自定义TypeScript模块和命名空间@typescript-eslint/no-namespace”。 是否有可能将其重写为import/export,如果可以,该如何操作?或者我应该禁用此规则来处理这种情况吗?
namespace Cypress
这一行,我希望它会声明一个与Cypress.Chainable
无关的新的Chainable
接口,所以我不能在Cypress.Chainable
值上调用该方法;或者你是指其他什么?(我现在无法尝试,但如果你认为有用的话,稍后可以尝试。) - Alexey RomanovallowDeclarations = true
吗?默认是false
。同时,你是否尝试过以不同的方式创建一个带有<declare module>
语法的单独的 d.ts 文件,并在 .ts 文件中直接使用它:///<reference path="../typings/custom/your.d.ts" />
,而不是将其放在全局上下文中? - Navoneel Talukdar