figma / plugin-typings

Typings for the Figma Plugin API
MIT License
195 stars 45 forks source link

Unable to use available console functions with current interface #311

Open CITguy opened 3 weeks ago

CITguy commented 3 weeks ago

There are several useful console functions available that I'm unable to use when developing a plugin, because the TypeScript interface is too limited.

The current interface only declares a subset of available functions.

interface Console {
  log(message?: any, ...optionalParams: any[]): void
  error(message?: any, ...optionalParams: any[]): void
  assert(condition?: boolean, message?: string, ...data: any[]): void
  info(message?: any, ...optionalParams: any[]): void
  warn(message?: any, ...optionalParams: any[]): void
  clear(): void
}

FYI: I'm not familiar enough with TypeScript to know if there's a way around this.

Isaiah-Turner commented 3 weeks ago

Ah, this is because we run plugin code in a javascript VM (here's a link to our blog post about it if you want to learn more!), so we have to overwrite console calls from inside the VM to actually print in the browser. We haven't overwritten these new methods, which is why you can't use them. I'll add this internally as a feature request. Thanks for the feedback!

CITguy commented 2 weeks ago

Ah, this is because we run plugin code in a javascript VM (here's a link to our blog post about it if you want to learn more!), so we have to overwrite console calls from inside the VM to actually print in the browser. We haven't overwritten these new methods, which is why you can't use them. I'll add this internally as a feature request. Thanks for the feedback!

Thanks for clarifying! I'm pretty new to plugin dev, so I was unaware of this. I wonder if it might help future noobs like myself if the interface were named something like VMConsole just to clarify that it's not an interface for the native console.