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

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.

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

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

var nodes = figma.currentPage.selection
nodes.forEach(n => {
    if (n.type == "INSTANCE") {
        var fill = n.fills[0]
    }
})

thats my code

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.

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