Skip to main content
Solved

Property 'fontName' does not exist on type 'BaseStyle'

  • August 11, 2022
  • 6 replies
  • 2534 views

Maxime_Daraize

Hello all,

I have this typescript error, but i am not sure what is mean, and how to resolve it. Any help would be appreciated. Thanks

Best answer by ntfromchicago

Ah, thanks for the clarification. The good news is that if your code works, it’s fine. That’s because your TypeScript gets compiled into JavaScript. So the error you see doesn’t exist in JS.

TypeScript is designed for syntax and type checking, so that warning appears because it thinks you are sending it a BaseStyle but you know (correctly) that it’s a TextStyle.

To make this error go away, just cast it explicitly as a TextStyle, e.g.

const aTextStyleFontFamily = (figma.getStyleById(id) as TextStyle).fontName.family

View original

6 replies

ntfromchicago

Did you mean to use getRangeTextStyleId instead from a TextNode?


Maxime_Daraize

Hello Nelson,
Thanks for the reply.

I want the property of the entire TextNode and not on character set of that TextNode.

So what i did was to find all TexT Styles and then compare their fontName.family Property to other element. What is confusing me its that everything is working as intended, but im still having this typescript error/warning message.

Is their any information on BaseStyle Type or why it might say that the property does not exist on it while in fact it does return something?


ntfromchicago
  • New Member
  • 287 replies
  • Answer
  • August 13, 2022

Ah, thanks for the clarification. The good news is that if your code works, it’s fine. That’s because your TypeScript gets compiled into JavaScript. So the error you see doesn’t exist in JS.

TypeScript is designed for syntax and type checking, so that warning appears because it thinks you are sending it a BaseStyle but you know (correctly) that it’s a TextStyle.

To make this error go away, just cast it explicitly as a TextStyle, e.g.

const aTextStyleFontFamily = (figma.getStyleById(id) as TextStyle).fontName.family


Gleb
  • Power Member
  • 4706 replies
  • August 13, 2022

Maxime_Daraize

Thank again for taking the time to answer. It is really helpful and explicitly asserting the time fixed the error 😀


Maxime_Daraize

Hi Gleb, thank you for the detail answer. Really appreciated it


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