variables2json-docs icon indicating copy to clipboard operation
variables2json-docs copied to clipboard

Request: Typescript declaration for exported variables

Open d01000100 opened this issue 2 years ago • 3 comments

¿Does a type declaration file for the exported variables already exists or is it planned?

i'm doing a Node.js/typescript script to process the exported variables and transform them into styles and having an existing type description of the result would be very handy to organize the logic and create type safe functions

d01000100 avatar Aug 18 '23 19:08 d01000100

Ill have a look and see if I can export my typescript classes that are used in the plugin before its converted to JSON. Would that help?

mark-nicepants avatar Aug 21 '23 06:08 mark-nicepants

@d01000100 are you automating the JSON download and file creation?

If you're only copy-and-pasting the exported JSON from Figma into a file, then tagging an as const onto the value might work even better.

const tokens = {
  version: '1.0.4',
  metadata: {},
  collections: [
    {
      name: 'Collection 1',
      modes: [
        {
          name: 'Mode 1',
          variables: [
            {
              name: 'Foo/bar',
              type: 'color',
              isAlias: false,
              value: '#F0A184',
            },
          ],
        },
      ],
    },
  ],
} as const;

doytch avatar Aug 22 '23 17:08 doytch

I'm not automating the JSON download ¿is there a way to do that? That would definitely make a more seamless pipeline to transform variables to stylesheets

Copying and pasting the output to a ts file does allow ts to type it, and I can inspect and destructure the object. However, I really would like to declare functions' paramaters and return types with the different structures of the result JSON.

I understand it wouldn't be a priority for a Figma plugin to have. I just asked to see if you already had it published somewhere.

For example, those are the types I've been extracting for my pipeline: types.d.txt. I was also asking to see if there were more properties I wasn't seeing in my examples.

Thank you for the response!

d01000100 avatar Aug 22 '23 17:08 d01000100