Skip to main content
Question

How to declare function in code.ts


Hi, I’m trying to create a helper function inside code.ts of my plugin like so:

However, I’m getting the error “cannot find the name updateUI” even though I’ve declared the function. Could someone please explain why this is not working?

This topic has been closed for replies.

3 replies

  • Author
  • 30 replies
  • June 26, 2023

[EDIT]: just declare void function without the void keyword and it’ll work!
Screenshot 2023-06-27 at 10.06.51 AM

To make my code more manageable, I decided to create an external file called helper.ts and imported the function in my code.ts like so:
Screenshot 2023-06-26 at 5.12.37 PM

In order for this to work, you have to set up your plugin project to allow code.ts to import external files (which is blocked by default due to Figma’s CSP). You can refer to this article on doing so using Webpack: Libraries and Bundling | Plugin API


Gleb
  • Power Member
  • 4708 replies
  • June 26, 2023

Regarding the initial question, the issue is you wrote void before function. This is not valid JS/TS syntax therefore it is not working. You don’t necessarily have to put it in another file.


  • Author
  • 30 replies
  • June 26, 2023

you’re right! I’ll edit my first post to reflect that!


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