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,
subject: props.subject,
html: await render(InviteReader({...props.props}))
})
}
}
}
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,
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?
3 Replies
Josh
Josh10mo ago
or do we just live with anys when doing super generic stuff
Solution
Josh
Josh10mo ago
No description
Josh
Josh10mo ago
Eh, this seems to work. Im happy enough with this
Want results from more Discord servers?
Add your server