figma / plugin-typings

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

TS2769: No overload matches this call, on "drop" event #289

Closed itsmnthn closed 5 months ago

itsmnthn commented 5 months ago

Typescript give error for registering drop event, says below

// "typescript": "^5.3.3",
// "@figma/plugin-typings": "^1.91.0",

// "build": "tsc -p tsconfig.json"

figma.on("drop", (event: DropEvent) => {/** something is here */})

code.ts:265:10 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '"drop"' is not assignable to parameter of type 'ArgFreeEventType'.

265 figma.on("drop", (event: DropEvent) => {
             ~~~~~~

  node_modules/.pnpm/@figma+plugin-typings@1.91.0/node_modules/@figma/plugin-typings/plugin-api.d.ts:59:3
    59   on(type: ArgFreeEventType, callback: () => void): void
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.

Screenshot 2024-04-24 at 11 41 30 AM

cyberalien commented 5 months ago

Can confirm that. Same issues with run, documentchange, stylechange, textreview events

Roystbeef commented 5 months ago

I think this is happening because the callback passed to figma.on("drop", ...) needs to return a boolean.

It should return false if it wants to handle the particular drop and stop Figma from performing the default drop behavior. https://www.figma.com/plugin-docs/api/properties/figma-on/#drop

for run, documentchange, stylechange, and textreview, it's expecting the callback passed to handle the event.

https://github.com/figma/plugin-typings/blob/master/plugin-api.d.ts#L51-L59 has a good breakdown of the expected types here

🤔 there's probably some work we could do to make the typescript errors here more clear - or make the callback requirements a bit less strict similar to how DOM events are handled but hopefully this unblocks ya'll for now!

cyberalien commented 5 months ago

Thanks!

Didn't notice line about returning false.