Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
4 replies
Josh

Generic type that extracts component props

Im tring to make a generator function that extracts the props of a component and adds in some extra stuff. The code is pretty straight forward
type ViewProps<T extends JSXElementConstructor<unknown>> = React.ComponentProps<T>
type EmailProps<T extends JSXElementConstructor<any>> = {
  to: string
  subject: string
  props: ViewProps<T>
}

export const emailer = {
  send: {
    InviteReader: async (props: EmailProps<typeof InviteReader>) => {
      await resend?.emails.send({
        to: props.to,
        from: "submissions@biblish.com",
        subject: props.subject,
        html: await render(InviteReader({...props.props}))
      })
    }
  }
}

This works as expected, where props.props is the properties of the InviteReader component. Is there a way i can do this while avoiding the
any
from EmailProps?
Was this page helpful?