Skip to content

TS issues in FR Gatherer Meta #12619

@adamraine

Description

@adamraine

A few days ago, we ran into an issue with distributed conditional types on FRTransitionalContext. This caused unexpected behavior when defining a gatherer with multiple dependencies.

The issues with FRTransitionalContext have been resolved by #12565 but this popped up again with GathererMeta.

export type GathererMeta<TDependencies extends DependencyKey = DefaultDependenciesKey> =
TDependencies extends DefaultDependenciesKey ?
GathererMetaNoDependencies :
GathererMetaWithDependencies<TDependencies>;

Multiple dependencies doesn't produce any errors, but the type is too lenient. For example, these are both valid according to our type definition:

/**
 * @type {LH.Gatherer.GathererMeta<'DevtoolsLog'|'Trace'>}
 */
this.meta = {
  supportedModes: ['timespan', 'navigation'],
  dependencies: {DevtoolsLog: DevtoolsLog.symbol, Trace: Trace.symbol},
}
/**
 * @type {LH.Gatherer.GathererMeta<'DevtoolsLog'|'Trace'>}
 */
this.meta = {
  supportedModes: ['timespan', 'navigation'],
  dependencies: {DevtoolsLog: DevtoolsLog.symbol},
}

Enforcing the expected behavior with square brackets fixes this, but it also opens pandora's box of other type violations. I haven't found a silver bullet to resolve these issues other than to keep the type definition of GathererMeta. Are these type violations valid, or can we stick with the weaker definition for GathererMeta?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions