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’.
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.
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.