lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Missing types for `category.supportedModes` and `node.explanation`

Open hilja opened this issue 1 year ago • 8 comments

FAQ

  • [X] Yes, my issue is not about variability or throttling.
  • [X] Yes, my issue is not about a specific accessibility audit (file with axe-core instead).

URL

https://clubmate.fi/about

What happened?

Not a big deal, but type defs for category.supportedModes and node.explanation fields seem to be missing. Also for www.theverge.com the node.explanation is not there (under the label-content-name-mismatch item). Apparently these are more rare fields.

Is this a mistake in the types or the output?

What did you expect?

Complete typing.

What have you tried?

I saved the output to a .ts file and added a type, then looked for the red squiglies:

import type Result from 'lighthouse/types/lhr/lhr.js'

const foo: Result = { /* LH output */ }
Screenshot 2024-02-02 at 19 21 55 Screenshot 2024-02-02 at 20 02 14

How were you running Lighthouse?

node

Lighthouse Version

11.5.0

Chrome Version

No response

Node Version

v20.11.0

OS

Mac OS

Relevant log output

No response

hilja avatar Feb 02 '24 19:02 hilja

The Lighthouse Config type allows supportedModes on each category but the Result type does not. TS is accurately reporting that the field is incorrect.

The explanation seems like an actual issues since we set it but it's not on the types: https://github.com/GoogleChrome/lighthouse/blob/main/core/audits/accessibility/axe-audit.js#L79

adamraine avatar Feb 02 '24 21:02 adamraine

Okay interesting. Could you elaborate on the Config a bit? Or point me to docs. I don't fully understand how to use that, or why am I seeing supportedModes in the results?

If I use Config.Category:

type CategoryConfig = Record<string, Config.Category>

Then it’s missing other properties like id and score.

I can extend the types and it seems to work:

type CategoryConfig = Record<string, Config.Category & Result.Category>

Is this correct usage?

Thanks!

hilja avatar Feb 03 '24 12:02 hilja

Okay interesting. Could you elaborate on the Config a bit? Or point me to docs. I don't fully understand how to use that, or why am I seeing supportedModes in the results?

Yeah I took a look at the generated results, and looks like we are emitting supportedModes on the result category even though it's not a part of the type. So I guess we should either remove that from the output or add supportedModes to the types.

adamraine avatar Feb 05 '24 17:02 adamraine

I'd like to have a take on this issue. I believe adding supportedModes would work better

An-Yay avatar Feb 26 '24 20:02 An-Yay

Feel free to submit a PR @An-Yay

adamraine avatar Mar 05 '24 23:03 adamraine

Please do it :) I just patched Lighthouse and forgot about it.

hilja avatar Mar 06 '24 10:03 hilja

Hey @adamraine,

I can pick the issue if it is still pending!

parshva-b avatar Apr 06 '24 07:04 parshva-b

Feel free to submit a PR @parshva-b

adamraine avatar Apr 08 '24 16:04 adamraine

G'day folks, I've raised a PR here for this fix. Please let me know if I've got it wrong. Cheers!

angad-sethi avatar May 20 '24 07:05 angad-sethi