figma / code-connect

A tool for connecting your design system components in code with your design system in Figma
MIT License
946 stars 68 forks source link

[1.2.0] type for render prop in figma.boolean is incorrectly inferred as `{}` #195

Open andrew-pledge-io opened 2 weeks ago

andrew-pledge-io commented 2 weeks ago

Given a figma connect configuration where figma.boolean is returning a function in one branch, e.g.:

import figma from '@figma/code-connect';

import { MyComponent } from './MyComponent.js';

figma.connect(MyComponent, 'https://www.figma.com/', {
  props: {
    render: figma.boolean('has a render prop', {
      true: (props: any) => <span {...props}>a render prop</span>,
      false: undefined,
    }),
  },
  example: (props) => <MyComponent render={props.render} />,
});

The type of props.render is {} which results in a type error:

  Type '{}' is not assignable to type '(props: unknown) => ReactNode'.
    Type '{}' provides no match for the signature '(props: unknown): ReactNode'.

In 1.1.4 the type was correctly inferred so this seems to be a regression.

tomduncalf-figma commented 2 weeks ago

Hey @andrew-pledge-io, thanks for the report. Sounds like a bug. We'll look into this and update you!