Skip to main content
Solved

Figma.mixed

  • January 19, 2022
  • 2 replies
  • 1936 views

Mark_Manfrey

I’m trying to retrieve the Style’s name for the fill color of text.

      let styleId = textNode.fillStyleId
      let styleName = figma.getStyleById(styleId).name

I get an error:
Argument of type ‘string | unique symbol’ is not assignable to parameter of type ‘string’.
Type ‘typeof figma.mixed’ is not assignable to type ‘string’.

I’ve tried defining styleId as a unique symbol (among other things), but basically keep running into the variable type conflict.

Any tips?

Best answer by Gleb

You need to check if the style is mixed and do something if it is like using the range functions to get styles of separate characters. TextNode · Figma Developers

let styleId = textNode.fillStyleId
if (styleId === figma.mixed) {
  // process each character individually 
  // or simply get the color of the first character
  styleId = textNode.getRangeFillStyleId(0, 1) as string
}
let styleName = figma.getStyleById(styleId).name
View original

2 replies

Gleb
  • Power Member
  • 4706 replies
  • Answer
  • January 19, 2022

You need to check if the style is mixed and do something if it is like using the range functions to get styles of separate characters. TextNode · Figma Developers

let styleId = textNode.fillStyleId
if (styleId === figma.mixed) {
  // process each character individually 
  // or simply get the color of the first character
  styleId = textNode.getRangeFillStyleId(0, 1) as string
}
let styleName = figma.getStyleById(styleId).name

Mark_Manfrey

Thank you, this helped a bunch


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