axe-playwright icon indicating copy to clipboard operation
axe-playwright copied to clipboard

Documented syntax doesn't work in TypeScript

Open ScubaDaniel opened this issue 2 years ago • 0 comments

The documentation suggest the following syntax is valid:

await checkA11y(page, null, {
  detailedReport: true,
})

When using this, I get a TypeScript error:

Argument of type 'null' is not assignable to parameter of type 'ElementContext | undefined'.ts(2345)

If I try to use undefined instead, it then complains that I don't provide axeOptions:

Argument of type '{ detailedReport: true; }' is not assignable to parameter of type 'Options'.
  Property 'axeOptions' is missing in type '{ detailedReport: true; }' but required in type 'axeOptionsConfig'.ts(2345)
index.d.ts(5, 3): 'axeOptions' is declared here.

Seems you need to make the axeOptions optional:

export interface axeOptionsConfig {
  axeOptions?: RunOptions
}

You'd also want to make context nullable:

export function checkA11y(
  page: Page,
  context?: ElementContext | null,
  options?: Options,
  skipFailures?: boolean,
): Promise<void>

ScubaDaniel avatar Jun 24 '22 15:06 ScubaDaniel