-
Notifications
You must be signed in to change notification settings - Fork 426
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
Better attribution type #414
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works for the issue in #408, but the better solution would be some variation on
export type MetricWithAttribution =
| CLSMetricWithAttribution
| FCPMetricWithAttribution
| FIDMetricWithAttribution
| INPMetricWithAttribution
| LCPMetricWithAttribution
| TTFBMetricWithAttribution;
I think we were considering that with the Metric
interface as well, but settled in doing that in a separate MetricType
. I don't totally remember why, though. Documentation? Or to avoid a breaking change?
If it's a top-level union, then it both fixes the type widening in #408, but also lets you narrow without an assertion, e.g. if you have a generic metricWithAttribution
you can check the name
so the compiler knows which metric it's dealing with
if (metricWithAttribution.name === 'LCP') {
const lcpEntry = metricWithAttribution.attribution.lcpEntry; // Property known to be present.
// ...
}
nbd if this isn't a path we want to go down today, but both Metric
and MetricWithAttribution
feel like they're leaving typescript functionality behind and making them slightly harder to use than they need to be.
Alternatively we could introduce a new It does seem odd to have both interfaces and types defined though but maybe that's OK in this case? @mcanu any thoughts here? |
Anyone any more thoughts on this? |
@brendankenny can you take a look at this and make a recommendation? I think any change here might be a breaking change, so it'd be good to get this in the v4 release if possible. |
Also, once we have a decision we can update this PR's base branch to the v4 branch. |
If there's going to be a breaking change, definitely switching to the unions at the top level would be ideal (e.g. get rid of I would love to give all the types a little refresh but I don't know if I'll have the time in the next ~24 hours if that's the goal for v4. |
CLosing in favour of #471 |
Fixes #408