Skip to content

Naming collision: Lighthouse exports Audit class and Audit namespace from the root #16923

@hilja

Description

@hilja

FAQ

URL

What happened?

Audit class and similarly named Audit namespace are both exported from the index:

import * as LH from '../types/lh.js';

export {Audit} from './audits/audit.js';

What did you expect?

When import type { Audit } from 'lighthouse' class takes precedence, making it impossible to use the Audit namespace.

What have you tried?

I can deep-import it from types/lh.js, but I'd rather not import from the internal implementation.

Some ideas

You could rename the Audit export to IAudit (NAudit whatever..), but that would probably be a breaking change, since the namespace can be exported like this:

export * from 'lighthouse/types/lh.js'
export as namespace LH

Could export types separately, package.json:

{
  "exports": {
    "types": "types/lh.js"
  }
}

Or mark Audit namespace deprecated over IAudit etc.

Also import/export eslint rule might catch collisions like this.

Or maybe there's a way to make TS prefer the namespace export that I don't know of.

How were you running Lighthouse?

node

Lighthouse Version

13.0.3

Chrome Version

No response

Node Version

No response

OS

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions