Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'XXXMetricWithAttribution' is not assignable to type 'MetricWithAttribution' #408

Closed
mcanu opened this issue Dec 21, 2023 · 1 comment

Comments

@mcanu
Copy link

mcanu commented Dec 21, 2023

When trying to be more generic and use MetricWithAttribution with FIDMetricWithAttribution (or other XXXMetricWithAttribution) I get this Typescript error:

Type 'FIDMetricWithAttribution' is not assignable to type 'MetricWithAttribution'.
  Types of property 'attribution' are incompatible.
    Type 'FIDAttribution' is not assignable to type '{ [key: string]: unknown; }'.
      Index signature for type 'string' is missing in type 'FIDAttribution'.

How to reproduce:

import { FIDMetricWithAttribution, MetricWithAttribution } from 'web-vitals/attribution';

const fidMetric: FIDMetricWithAttribution = {...};
const metricWithAttribution: MetricWithAttribution = fidMetric;

I fixed this by creating a "new" MetricWithAttribution with the correct types:

import {
  CLSAttribution,
  FCPAttribution,
  FIDAttribution,
  FIDMetricWithAttribution,
  INPAttribution,
  LCPAttribution,
  Metric,
  TTFBAttribution,
} from 'web-vitals/attribution';

interface MetricWithAttribution extends Metric {
  attribution:
    | FIDAttribution
    | CLSAttribution
    | LCPAttribution
    | TTFBAttribution
    | INPAttribution
    | FCPAttribution;
}

const fidMetric: FIDMetricWithAttribution = {};
const metricWithAttribution: MetricWithAttribution = fidMetric;

The existing MetricWithAttribution definition should be updated or fixed to accommodate these use cases.

@tunetheweb
Copy link
Member

Resolved with #471. Will be included in v4 as breaking change to the types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants