Skip to main content
August 1, 2023
Question

Cant access fills

hey,

I am trying to access the color value of an instance. However, when I try to access the first Paint object with node.fills[0] I get the following error.

My code:
var node = Figma.currentPage.selection[0];
var e = (node).fills;
e[0] ← error here

Element implicitly has an ‘any’ type because expression of type ‘0’ cannot be used to index type ‘readonly Paint | unique symbol’.
Property ‘0’ does not exist for type ‘readonly Paint | unique symbol’.

hope someone can help

This topic has been closed for replies.

6 replies

tank666
August 1, 2023

Are you getting this error in your IDE? Are you using TypeScript? Specify in code what type of node should be. Add a condition to check the existence of the fills property and its array length.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Robin21Author
August 2, 2023

yes in IDE and im using TS. It is specified as InstanceNode

tank666
August 2, 2023

I don’t see it in the code you provided.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Robin21Author
August 2, 2023
var nodes = figma.currentPage.selection
nodes.forEach(n => {
    if (n.type == "INSTANCE") {
        var fill = n.fills[0]
    }
})

thats my code

tank666
August 2, 2023

You don’t check for the length of the array. For example, one InstanceNode has fill at index 0, and the second InstanceNode has no fill, so index 0 cannot be found in that node.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Gleb
Power Member
August 2, 2023

Nope, the error is about the mixed type fill. You need to check if it’s mixed because if it is, you can’t iterate it like an array.

Similar to this: Figma.mixed - #2 by Gleb