figma / plugin-typings

Typings for the Figma Plugin API
MIT License
195 stars 45 forks source link

TS Error: 'properties' does not exist on type 'DocumentChange' #194

Closed xaviervalarino closed 1 year ago

xaviervalarino commented 1 year ago

Been getting this error while subscribing to the documentchange event, but I know it's in the docs and in the log.

Screenshot 2023-02-20 at 10 42 25 PM Screenshot 2023-02-20 at 10 44 06 PM

I tried:

npm rm @figma/plugin-typings
npm i -D @figma/plugin-typings

but that didn't do much.

I'm using node v19.6.0

ymichael commented 1 year ago

Hi @xaviervalarino, I believe the reason typescript is unhappy here is because not all types in documentChanges have a "properties" attribute.

Here's more information on all the different types of changes that might appear in e.documentChanges: https://www.figma.com/plugin-docs/api/DocumentChange/

Try this instead:

figma.on("documentchange", (e) => {
  for (const change of e.documentChanges) {
    if (change.type === "PROPERTY_CHANGE") {
      const properties = change.properties;
      // DO STUFF
    }
  }
});
xaviervalarino commented 1 year ago

That fixed it. Thank you very much