Fixed Sx type: added support of predefined aliases#294
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Frosty21
left a comment
There was a problem hiding this comment.
Only question i have is the replacing "width" as "w" i would go for "width" as its more descriptive
|
Hey, you can use the |
|
@nandorojo the issue is related only to typings of built-in aliases. All of these aliases are valid in JS code, and even in TS code it will work, BUT, TypeScript will complain on it, because these types are missed (only types, not aliases). This PR fixes that. |
| | keyof ViewStyle | ||
| | keyof TextStyle | ||
| | keyof ImageStyle | ||
| | keyof Omit<Aliases, Object.SelectKeys<Aliases, NonStyleableSxProperties>> |
There was a problem hiding this comment.
Sorry for the late review. This could just just use Pick right?
It's a bit tricky to review all this and know it's working haha TS is so hard to look at in that way
There was a problem hiding this comment.
@nandorojo Do you mean to replace Object.SelectKeys<Aliases, NonStyleableSxProperties> with keyof Pick<Aliases, NonStyleableSxProperties>>?
This will not work, because Pick selects by keys, while Object.SelectKeys selects by values, which is required for the map of aliases.
As the alternative solution, the aliases object can be split into 2 ones: styleable and non-styleable, and then this line can be replaced with:
| | keyof Omit<Aliases, Object.SelectKeys<Aliases, NonStyleableSxProperties>> | |
| | keyof StyleableAliases |
Hi @nandorojo
First of all, thank you for your work on this great project!
I found a typing issue with the
Sxprop related to aliases. For now, only the aliases of theme-ui are allowed by TS (bg,m,mt,mr,mb,ml,mx,my,p,pt,pr,pb,pl,px,py,size), all other defined aliases (likeh,w,br) are not exposed toSxtype, and TS will complain when you will try to use it, however aliasing will work.This PR fixes this issue, allowing to use TS intellisense for predefined aliases.