Skip to content

Is it possible to infer variants from createStyleSheet as component props types #150

Closed Answered by jpudysz
bryanprimus asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! I didn't expose the type, but Unistyles indeed infers the type for the useStyles hook. It's called ExtractVariantNames, and you can find it here:

export type ExtractVariantNames<T> = T extends (...args: any) => infer R

You need to pass typeof stylesheet to it. Nonetheless, I think it's easier to simply type your props because you also need to select the variant name from the result.

In this case, I believe simplicity is more important than complexity.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jpudysz
Comment options

Answer selected by bryanprimus
@bryanprimus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants