code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

Template V2 - TypeScript inference when writing Code Connect file with Template V2 API

Open amoshydra opened this issue 11 months ago • 0 comments

Describe the feature you'd like:

Understood from https://www.figma.com/code-connect-docs/template-v2-api/ it is possible for us to create raw Code Connect file.

Is it possible to also publish the types for these API via npm?

Usage

// url=https://www.figma.com/file/your-file-id/Component?node-id=123
const figma = require('figma')
const instance = figma.selectedInstance // <--- allowing this to be properly typed

Workaround

Current workaround is to recreate most of the types by referencing the same document.

Then configure a to refer to it:

{
  "compilerOptions": {
    "composite": true,
    "module": "Node16",
    "moduleResolution": "node16",
    "allowJs": true,
    "checkJs": true,
    "types": [
      "./figma.template.d.ts",
    ]
  },
  "include": ["src/**/*.figma.template.js"],
}

and have a figma.template.d.ts containing all additional declaration

Sharing an example of figma.template.d.ts https://gist.github.com/amoshydra/9f19ec3f9395618c51532bd568e3e647#file-figma-template-d-ts

amoshydra avatar Mar 15 '25 13:03 amoshydra