-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): add sx prop whenever className can be string #1308
Conversation
packages/core/src/jsx-namespace.ts
Outdated
? Omit<P, keyof SxProps> & SxProps | ||
: Omit<P, keyof SxProps> | ||
: Omit<P, keyof SxProps> | ||
export type WithConditionalSxProp<P> = { className: string } extends P |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this one much more than the previous solution. I don't know why Emotion did it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, Dany. Now it's even uglier. I forgot that components can have more than one prop while writing this, and that's how I got that nice one-liner :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha 😂
Okay, I got greedy, and there's going to be another change, what you can probably see in failed tests. I'm making |
cc @beerose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeScript changes look good to me
I'm not exactly sure if we have the best possible implementation, as we don't produce
className
at runtime, we producecss
and call Emotion'sjsx
, so it seems that we should also use their types for correctness.cc @atanasster @dcastil
Relevant to #1307, but I'm not sure if it closes.
There are three changes here.
The change to
WithPoorAsProp
allows to read props of@theme-ui/mdx
Styled
on type level. Previously, after passing throught ComponentProps, they became dicts ofunknown
.The change to
WithConditionalSxProp
allows to usesx
with all components acceptingclassName
of typestring
, even if they also accept other values forclassName
.