Code Monkey home page Code Monkey logo

Comments (6)

tunetheweb avatar tunetheweb commented on September 23, 2024

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.

OliverJAsh avatar OliverJAsh commented on September 23, 2024

@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.

tunetheweb avatar tunetheweb commented on September 23, 2024

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.

OliverJAsh avatar OliverJAsh commented on September 23, 2024

That fixes it! 🚀

from web-vitals.

tunetheweb avatar tunetheweb commented on September 23, 2024

@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.

OliverJAsh avatar OliverJAsh commented on September 23, 2024

Just checked, it still works 😄 Thank you!

from web-vitals.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.