axe.run() overrides produce misleading Typescript warnings
See original GitHub issueWe are using the latest version of axe-core in our TS Protractor tests directly, since using axe-webdriverjs’s AxeBuilder throws TS compilation issues. To use axe, we declare it as a const of type any:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const axe: any;
any we use it in a function like so:
return browser.executeAsyncScript((opts: A11YOptions, done: (arg0: Promise<AxeResults>) => void) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
const req: Promise<AxeResults> = axe.run(document, opts);
done(req);
}, options);
Above, we provide it with the HTML document as the context and an options object with some rules to be disabled. Despite the code running, the TS compiler in the IDE warns that axe.run() expects 0 or 1 arguments, whereas in reality according to the overrides and the documentation it can accept anywhere between 0 and 3 (context, options and a callback).
Looking at the overloads for .run():

… we were wondering if it had something to do with the overloads ordering (https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#function-overloads), and if the function types should be more open by making use of optional params and union types?
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (5 by maintainers)

Top Related StackOverflow Question
Going to close as it looks like this is resolved. Please re-open if that is not the case.
Hi @michael-siek - thanks for taking a look. I actually did try that before without success, but I have now noticed that was because my declared type of
optswas incompatible with what the overloads were expecting (I didn’t see that axe provided aRunOptionsinterface, so I created my own, which is incompatible). I now have no warnings or errors 😃