Skip to main content
Question

createVariableAlias behaves inconsistently with variants


Jiri_Trecak

Hey!

First of all, good job on the new API improvements. I am building something with variables and upon using figma.variables.createVariableAlias, I found inconsistent behavior between the editor interface and this method.

Specifically, I am trying to assign variables to the InstanceNode (here, “Mode” prop key):

properties["Mode"] = figma.variables.createVariableAlias(variable)

This works, for string properties. For numeric properties, however, an error is thrown stating that the property that I am trying to assign can’t resolve to “string”. Now I assume this is because the API requires only string properties to be assigned (Working with Variables | Plugin API) - just an assumption - however this limitation doesn’t exist when using the editor:

CleanShot 2023-06-23 at 14.57.23

In editor, numeric variable can be bound just fine. This is quite a big limitation, because any real conditionals will usually work with numbers.

Possibly I am missing something, but this seems like a bug in the SDK layer to me.

Thank you!

3 replies

James_Yang
Figmate
  • Figmate
  • 82 replies
  • July 21, 2023

Thanks for reporting this! This is an API bug that we plan to fix.


Voit_F_Florian

@James_Yang any updates on this?


James_Yang
Figmate
  • Figmate
  • 82 replies
  • September 9, 2023

After looking into this, this is currently an expected limitation of the plugin API.

The UI does some additional work (using a string-ification expression) to make numeric variables work in these kinds of bindings. To support the same behavior in the plugin API, we need to make these number → string conversions explicit and implement an expressions system. This is something we plan to do, but with the amount of work involved, unfortunately it’s not coming anytime soon.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings