Skip to main content
Solved

Editing properties doesn't work as explained in doc


Michael_Gubik

Pasting this code from the documentation on Accessing the Document does not work.

for (const node of figma.currentPage.selection) {
  if ("opacity" in node) {
    node.opacity *= 0.5
  }
}

Cannot assign to ‘opacity’ because it is a read-only property

How to do it?

Best answer by Gleb

TypeScript doesn’t know that.

And this may help:

View original

3 replies

Gleb
  • Power Member
  • 4709 replies
  • May 4, 2022

This happens because some nodes don’t allow opacity modification.

E.g. ConnectorNode (I guess it’s all nodes from FigJam): ConnectorNode · Figma Plugins

You need to ensure the node type is the one with not readonly opacity so TypeScript doesn’t give you a warning. You can filter selection to include only the node types your plugin accepts.


Michael_Gubik

This problem occurs even with a simple RectangleNode that should allow setting opacity.


Gleb
  • Power Member
  • 4709 replies
  • Answer
  • May 13, 2022

TypeScript doesn’t know that.

And this may help:


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings