Editing properties doesn't work as explained in doc

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?

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.

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

TypeScript doesn’t know that.

And this may help:

1 Like