GoogleChrome / web-vitals

Essential metrics for a healthy site.
https://web.dev/vitals
Apache License 2.0
7.55k stars 414 forks source link

Update types to support more generic usage #471

Closed brendankenny closed 5 months ago

brendankenny commented 5 months ago

Fixes #408

Relatively light type clean up for v4. Things are looking pretty good and I ended up not changing that much, which is great. For many use cases there won't be breaking changes here in practice (e.g. if you already had a LCPMetric specifically, the name of the base interface or a union it might belong to doesn't matter).

It's possible some things still went too far for some sensibilities; let me know and I can just roll those back. Once this is looking good, I'll update the README entries around these.

Changes:

brendankenny commented 5 months ago

We could have the attribute* methods return the newly attributed object to avoid the extra type assertion, but I wasn't sure if that was too big a change.

I like this way better, actually, so I added it. Separate commit so it's easy to remove, though.

brendankenny commented 5 months ago

The main thing missing right now is to copy the type changes to the relevant parts of the README documentation

PTAL

philipwalton commented 5 months ago

@brendankenny I made some updates to your updates (and merged in @tunetheweb's test fixes). Let me know if you have any concerns with any of the changes I made.

tunetheweb commented 5 months ago

Oh and just realised there's a merge conflict due to #468 being merged.

philipwalton commented 5 months ago

Actually I ended up just removing all the links to the source types because it looks like they no longer work with GitHub's new file viewer UI.