figma / plugin-typings

Typings for the Figma Plugin API
MIT License
190 stars 44 forks source link

Please include plugin typings as a module or additional README instructions #294

Closed dfernandez79 closed 3 months ago

dfernandez79 commented 3 months ago

The README instructions indicate that you should use typeRoots to access the Figma plugin types because they are part of the host environment.

However, file paths are problematic when the project is in a monorepo because the @figma directory inside node_modules may be hoisted. Since TypeScript 5.1, the lookup upward is disabled: https://devblogs.microsoft.com/typescript/announcing-typescript-5-1/#explicit-typeroots-disables-upward-walks-for-node_modules-types

An alternative is to use types and specify the global packages. However, using @figma/plugin-typings alone will not work as the plugin-api types are referenced but not exported. Library users should also add @figma/plugin-typings/plugin-api to types if they want this option.

I understand the reason for the global types, and it's necessary for global objects like figma or __uiFiles__.

However, for the plugin API, the DX is much better if users can do the following:

import type {Variable} from "@figma/plugin-typings";

The benefits are:

If that is not an option, additional instructions in the README file could be helpful. (I can volunteer to do a first pass for that).

ahurtado-figma commented 3 months ago

Hey @dfernandez79 -- thank you for your suggestion! I chatted with the rest of the team about this change.

Ideally, we agree that being able to do import type {Variable} from "@figma/plugin-typings"; is much better developer experience than what we currently have so far. However, we are a bit concerned that it might be a breaking change, and we're hesitant to take on something with that sort of maintenance complexity.

However! If you'd like to write up a README change with additional instructions, we'd be happy to consider it 🙂