Cypress documentation shows how to declare custom command types:
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>
}
}
}
But Typescript ESLint is unhappy about this due to "ES2015 module syntax is preferred over custom TypeScript modules and namespaces @typescript-eslint/no-namespace". Is it possible to rewrite this to import/export and if so, how? Or should I just disable the rule for this case?
namespace Cypressline, I expect it would declare a newChainableinterface unrelated toCypress.Chainableand so I couldn't call the method on aCypress.Chainablevalue; or do you mean something else? (I can't try it right now, but can later if you think it's useful.)allowDeclarations = true, by default it'sfalse. Also in a different way instead of putting this in global context , did you try creating a separate d.ts file withdeclare module <>like syntax and then using directly in a .ts file:///<reference path="../typings/custom/your.d.ts" />