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

Fix attribution types #348

Merged
merged 3 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it was missed previously. All the other metrics apart from CLS have this set correctly.

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;
}