You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
When using the sx prop, the useThemeUI hook, or any other API that exposes the theme object, it would be really nice to have a way to set a custom theme type for that object on a project-wide basis. So when I write
<divsx={{backgroundImage: ({colors: { red, blue }})=>`linear-gradient(to right, red, blue)`}}/>
Describe the solution you'd like
We should somehow be able to use generics to solve this problem:
Leave out the ambient type that extends JSX elements with the sx prop. Explain how to extend the JSX interface with your own theme type in the docs. It should look something like this (whereas SxPropsisn't currently generic):
import{SxProps}from'@theme-ui/core';declare module 'react'{interfaceDOMAttributes<T>extendsSxProps<MyTheme>{}}declare global {namespaceJSX{interfaceIntrinsicAttributesextendsSxProps<MyTheme>{}}}
Rewrite the useThemeUI hook in a way that takes advantage of a generic type and explain how to use this feature in the docs. Something like:
Repeat step 2 for all the other functions/API's in the Theme UI ecosystem that are currently hardwired to use the non-generic Theme type. For example, @theme-ui/color.
Note that my proposed solution is an opt-in approach. The generic types should all fall back to the default Theme type, both to preserve current behavior and to allow for correct typing in scenarios where you genuinely don't know what properties will be available on a theme object. The latter may occur, for example, when using unvalidated, user-authored themes.
Is your feature request related to a problem? Please describe.
When using the
sx
prop, theuseThemeUI
hook, or any other API that exposes the theme object, it would be really nice to have a way to set a custom theme type for that object on a project-wide basis. So when I writetsc
shouldn't throw an error, which it currently does because the defaultTheme
type's properties are all optional (so the compiler has no way of knowing whethercolors
exists on the theme object).Describe the solution you'd like
We should somehow be able to use generics to solve this problem:
sx
prop. Explain how to extend the JSX interface with your own theme type in the docs. It should look something like this (whereasSxProps
isn't currently generic):useThemeUI
hook in a way that takes advantage of a generic type and explain how to use this feature in the docs. Something like:Theme
type. For example,@theme-ui/color
.Describe alternatives you've considered
I developed a brute-force workaround by disabling Theme UI's types in
tsconfig.json
and manually redefining the ones that define the theme object and related API's.Additional context
Original issue described here: #1188 (comment)
The text was updated successfully, but these errors were encountered: