Comments (6)
Could you please explain how you're seeing this error? I tried creating a new project with the above example snippet in a test.js
file and then run the following:
$ npm install [email protected]
changed 1 package, and audited 3 packages in 573ms
found 0 vulnerabilities
$ tsc --strict test.ts
\test.ts:5:10 - error TS2339: Property 'attribution' does not exist on type 'Metric | CLSMetric | CLSMetricWithAttribution'.
Property 'attribution' does not exist on type 'Metric'.
5 metric.attribution.largestShiftTarget;
~~~~~~~~~~~
Found 1 error in test.ts:5
The same thing with 3.3.2 does not happen:
$ npm install [email protected]
changed 1 package, and audited 3 packages in 678ms
found 0 vulnerabilities
$ tsc --strict test.ts
$
from web-vitals.
@tunetheweb Apologies, there was a typo in my original post. I've corrected it now so hopefully it makes a bit more sense.
To clarify, we're expecting the type of largestShiftTarget
to be string | undefined
but if you hover over you will see it's unknown
.
This is in a brand new project with nothing but the latest versions of typescript
and web-vitals
.
Here's an adjusted example which generates a type error:
import { onCLS } from "web-vitals/attribution";
onCLS((metric) => {
// Error: Type 'unknown' is not assignable to type 'string | undefined'.
const x: string | undefined = metric.attribution.largestShiftTarget;
});
from web-vitals.
OK so it appears you can't just change a type of an interface in Typescript by repeating it. By removing the extends
you only have one metric
and TypeScript is able to work properly.
However, that causes other problems (web-vitals.js will not build) so the answer appears to be a little trickier.
Can you try the branch from this PR and let me know if that works?
#356
from web-vitals.
That fixes it! 🚀
from web-vitals.
@OliverJAsh I updated the PR with your original suggestion. Not sure why couldn't get your suggestion to work previously but could you double check that branch still works to solve your issue before I merge this to save us having a third attempt at this?
from web-vitals.
Just checked, it still works 😄 Thank you!
from web-vitals.
Related Issues (20)
- Allow to reset the INP calculation HOT 2
- v4 giving undefined TypeError HOT 1
- INP: Probably a bad measurement metric for web vitals - even with simple HTML structure pages with no CSS will cause bad value. HOT 1
- Expose INP target element as first class citizen in attribution HOT 3
- Expose ability to reset internal state of metrics (specifically INP) HOT 2
- v4 INP attribution ending processingEnd time in the wrong animation frame HOT 8
- CDN JS - Web server is returning an unknown error HOT 4
- CLS and INP are being calculated incorrectly HOT 2
- Suggestion to track all attributions HOT 4
- CLS being reported due to filter CSS transition HOT 3
- Firefox e2e tests flakey HOT 3
- can't find ReportCallback or ReportHandler type HOT 3
- Are there any updates for soft-navs? HOT 2
- LoAF missed for some INP events HOT 9
- Facing issue while exporting `web-vitals/attribution` using `browserify` HOT 2
- LoAF Performance entry script sourceFunctionName and sourceURL logged values HOT 4
- Using `performance.eventCounts` instead of `performance.interactionCount` HOT 2
- Heads Up on Changes to INP Measurement When Interfered with JS Modal Dialogs HOT 9
- TypeError: Cannot read properties of undefined (reading 'processingEnd') HOT 13
- TypeScript 5.5 compatibility
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-vitals.