question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

axe.run() overrides produce misleading Typescript warnings

See original GitHub issue

We 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(): Screen Shot 2020-06-19 at 10 34 19

… 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:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
strakercommented, Jul 28, 2020

Going to close as it looks like this is resolved. Please re-open if that is not the case.

1reaction
ge-vlad-romanovcommented, Jul 28, 2020

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 opts was incompatible with what the overloads were expecting (I didn’t see that axe provided a RunOptions interface, so I created my own, which is incompatible). I now have no warnings or errors 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axe API Documentation - Deque Systems
Provides list of rules and elements that passed accessibility checking, ensuring rules have been run against entire document; Only checks rendered content to ......
Read more >
axe-playwright - npm
Start using axe-playwright in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type ...
Read more >
axe-core | Yarn - Package Manager
Axe is open source. It returns zero false positives (bugs notwithstanding). It's designed to work on all modern browsers and with whatever tools,...
Read more >
Tools to catch accessibility errors in JavaScript applications
How to use automated tooling to catch accessibility issues in a web application built with React, Vue or other JavaScript frameworks.
Read more >
VSCODE shows warnings as errors - typescript - Stack Overflow
There must be a way to make warnings show up as warnings and errors as errors. – Rosenpin. Aug 11 at 12:31. well...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found