Skip to content

Commit

Permalink
Fix attribution types (#348)
Browse files Browse the repository at this point in the history
* Fix attribution types

* Fix CLS

* Revert version update
  • Loading branch information
tunetheweb authored May 29, 2023
1 parent 64f1335 commit 5154ee3
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/attribution/onCLS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const onCLS = (
opts?: ReportOpts
) => {
unattributedOnCLS(
((metric: CLSMetric) => {
((metric: CLSMetricWithAttribution) => {
attributeCLS(metric);
onReport(metric);
}) as CLSReportCallback,
Expand Down
4 changes: 4 additions & 0 deletions src/types/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export interface ReportCallback {
(metric: Metric): void;
}

export interface ReportCallbackWithAttribution {
(metric: MetricWithAttribution): void;
}

export interface ReportOpts {
reportAllChanges?: boolean;
durationThreshold?: number;
Expand Down
10 changes: 8 additions & 2 deletions src/types/cls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import {LoadState, Metric, ReportCallback} from './base.js';
import {
LoadState,
Metric,
ReportCallback,
ReportCallbackWithAttribution,
} from './base.js';

/**
* A CLS-specific version of the Metric object.
Expand Down Expand Up @@ -83,6 +88,7 @@ export interface CLSReportCallback extends ReportCallback {
/**
* A CLS-specific version of the ReportCallback function with attribution.
*/
export interface CLSReportCallbackWithAttribution extends CLSReportCallback {
export interface CLSReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: CLSMetricWithAttribution): void;
}
10 changes: 8 additions & 2 deletions src/types/fcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import {LoadState, Metric, ReportCallback} from './base.js';
import {
LoadState,
Metric,
ReportCallback,
ReportCallbackWithAttribution,
} from './base.js';
import {NavigationTimingPolyfillEntry} from './polyfills.js';

/**
Expand Down Expand Up @@ -75,6 +80,7 @@ export interface FCPReportCallback extends ReportCallback {
/**
* An FCP-specific version of the ReportCallback function with attribution.
*/
export interface FCPReportCallbackWithAttribution extends FCPReportCallback {
export interface FCPReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: FCPMetricWithAttribution): void;
}
10 changes: 8 additions & 2 deletions src/types/fid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import {LoadState, Metric, ReportCallback} from './base.js';
import {
LoadState,
Metric,
ReportCallback,
ReportCallbackWithAttribution,
} from './base.js';
import {FirstInputPolyfillEntry} from './polyfills.js';

/**
Expand Down Expand Up @@ -76,6 +81,7 @@ export interface FIDReportCallback extends ReportCallback {
/**
* An FID-specific version of the ReportCallback function with attribution.
*/
export interface FIDReportCallbackWithAttribution extends FIDReportCallback {
export interface FIDReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: FIDMetricWithAttribution): void;
}
10 changes: 8 additions & 2 deletions src/types/inp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import {LoadState, Metric, ReportCallback} from './base.js';
import {
LoadState,
Metric,
ReportCallback,
ReportCallbackWithAttribution,
} from './base.js';

/**
* An INP-specific version of the Metric object.
Expand Down Expand Up @@ -75,6 +80,7 @@ export interface INPReportCallback extends ReportCallback {
/**
* An INP-specific version of the ReportCallback function with attribution.
*/
export interface INPReportCallbackWithAttribution extends INPReportCallback {
export interface INPReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: INPMetricWithAttribution): void;
}
5 changes: 3 additions & 2 deletions src/types/lcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Metric, ReportCallback} from './base.js';
import {Metric, ReportCallback, ReportCallbackWithAttribution} from './base.js';
import {NavigationTimingPolyfillEntry} from './polyfills.js';

/**
Expand Down Expand Up @@ -98,6 +98,7 @@ export interface LCPReportCallback extends ReportCallback {
/**
* An LCP-specific version of the ReportCallback function with attribution.
*/
export interface LCPReportCallbackWithAttribution extends LCPReportCallback {
export interface LCPReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: LCPMetricWithAttribution): void;
}
5 changes: 3 additions & 2 deletions src/types/ttfb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Metric, ReportCallback} from './base.js';
import {Metric, ReportCallback, ReportCallbackWithAttribution} from './base.js';
import {NavigationTimingPolyfillEntry} from './polyfills.js';

/**
Expand Down Expand Up @@ -76,6 +76,7 @@ export interface TTFBReportCallback extends ReportCallback {
/**
* A TTFB-specific version of the ReportCallback function with attribution.
*/
export interface TTFBReportCallbackWithAttribution extends TTFBReportCallback {
export interface TTFBReportCallbackWithAttribution
extends ReportCallbackWithAttribution {
(metric: TTFBMetricWithAttribution): void;
}

0 comments on commit 5154ee3

Please sign in to comment.