Skip to main content

Hello,


I am trying to apply grid variable using below code by following Working with Variables | Plugin API guide.


Error : Expected “layoutPattern” to have type “GRID” but got string instead


We are trying to create a copy of layoutgrid and apply new variable using below code


let propCopy = p...node.layoutGrids];
propCopyp0] = figma.variables.setBoundVariableForLayoutGrid(
propCopyp0],
"gutterSize",
variable
);
node.layoutGrids = propCopy;

propCopyp0] is as below


{alignment: "STRETCH",
boundVariables: {offset: {…}, sectionSize: {…}, count: {…}, gutterSize: {…}},
color: {r: 1, g: 0, b: 0, a: 0.10000000149011612},
count: 4,
gutterSize: 20,
offset: 100,
pattern: "ROWS",
visible: true}

But after executing, we are getting below error:


in setBoundVariableForLayoutGrid: Expected "layout…ttern" to have type "GRID" but got string instead
mesage: "in setBoundVariableForLayoutGrid: Expected "layoutGridCopy" to be one of the following, but none matched: \n Expected "layoutGridCopy.alignment" to be one of the following, but none matched: \n Expected "layoutGridCopy.alignment" to have type "MIN" but got string instead\n Expected "layoutGridCopy.alignment" to have type "MAX" but got string instead\n Expected "layoutGridCopy.boundVariables" to have type {gutterSize: (optional) {id: string, type: "VARIABLE_ALIAS"}, count: (optional) {id: string, type: "VARIABLE_ALIAS"}, offset: (optional) {id: string, type: "VARIABLE_ALIAS"}} but got additional property "sectionSize"\n Expected "layoutGridCopy.alignment" to have type "CENTER" but got string instead\n Expected "layoutGridCopy.pattern" to have type "GRID" but got string instead"

Please help.


Thank you

[quote=“Figterate, post:2, topic:68498, full:true”]

We checked it again by manually updating layout grid one by one for each property. And found that it is causing error only for below use case:



  1. Select ROW pattern and MIN alignment (top type in UI), apply variable in offset and size

  2. Change alignment to CENTER and then use setBoundVariableForLayoutGrid to update size variable.


In this case boundVariable still contains offset entry but in CENTER it should be ignored. We also tried to remove it by passing null to setBoundVariableForLayoutGrid as below but in this case also we got same error


setBoundVariableForLayoutGrid: Expected "layout…ttern" to have type "GRID" but got string instead


layoutGrid = figma.variables.setBoundVariableForLayoutGrid(
layoutGrid,
"offset",
null
);

Same happened with STRETCH alignment and having variable attached in sectionSize.


@Figterate The same is happening to me, did you find a solution to this, or is it a bug? If so, have you reported it directly to Figma?


Reply