-
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
0.5.0-alpha.1 - Property 'sx' does not exist on type 'IntrinsicAttributes & ... #1307
Comments
Okay, so I have one case of this bug, and I think I have a suspect. I didn't check if it's the same thing that happens in my case and the investigationimport { jsx, Styled as s } from "theme-ui";
export type BoxedTextProps = ComponentPropsWithoutRef<typeof s.p>; My Simple, right? Well, no. I must have wrote it before export interface ThemedComponent<Name extends ElementType> {
<As extends ElementType | undefined = undefined>(props: WithPoorAsProp<ComponentProps<Name>, As>): JSX.Element;
}
export declare type WithPoorAsProp<Props, As extends ElementType | undefined = undefined> = {
as?: As;
} & (As extends undefined ? Props : AnyComponentProps);
interface AnyComponentProps extends JSX.IntrinsicAttributes {
[key: string]: unknown;
}
But the problem with it is that when we read the props on type level, as becomes Okay, but it should allow any prop, right? declare type WithConditionalSxProps<P> =
'className' extends keyof P
? P extends { className?: string; }
? Omit<P, 'sx'> & { sx: SxProps }
: Omit<P, keyof 'sx'>
: Omit<P, 'sx'>;
export declare namespace ThemeUIJSX {
type LibraryManagedAttributes<C, P> = WithConditionalSxProps<P> & ReactJSXLibraryManagedAttributes<C, P>;
}
This is one example of such component. const PropsToJson = (props: Record<string, unknown>) => <pre>{JSON.stringify(props, null, 2)}</pre> We do transform our
Let's take a look at declare type WithConditionalSxProps<P> =
'className' extends keyof P
? P extends { className?: string; }
? Omit<P, 'sx'> & { sx: SxProps }
: Omit<P, keyof 'sx'>
: Omit<P, 'sx'>; We need to change We can read
Take a look at this TS Playground.. I'll rewrite it to tests in our repo. This leads me to another observation. We could also fix that problem of mapping props to undefined with AnyComponentProps. Digression Even if we "support" |
Okay, I pulled component-controls and checked what's happening on your side @atanasster. Neither export type PopoverProps = PopoverOwnProps &
Omit<Partial<TooltipTriggerProps>, 'children'>; The type of props you define actually doesn't match what you do at runtime. export const Popover: FC<PopoverProps> = ({
arrowVisible = true,
trigger,
placement = 'bottom',
modifiers,
tooltip,
children,
tooltipShown,
onVisibilityChange,
...props
}) => { You extract We could define the type as so interface PopoverProps extends
PopoverOwnProps,
Pick<
TooltipTriggerProps,
'trigger' | 'placement' | 'modifiers' | 'tooltip' | 'tooltipShown' | 'onVisibilityChange'
>,
BoxProps
{
// you could specifiy own props here if you don't need to export them separately
} |
Great - I am in the middle of a large coding and will try it asap = possibly tomorrow. Any specific reason sx is not global anymore? |
Previously it was global even in files without JSX pragma. That was quite error-prone. Right now |
ahhh thanks, makes sense now |
import {} from 'react'
import { ThemeUIStyleObject } from 'theme-ui'
declare module 'react' {
interface Attributes {
sx?: ThemeUIStyleObject
}
} I'm wondering if we should add a snippet above in one easy to import file to allow users to opt-in to global |
@hasparus I personally would love it |
I also think it would be a good idea to expose an importable TS file as an escape hatch. Emotion did the same, I think their code is even the same as in your example. |
just a note, I was unable to quickly move to the new For now, I am re-declaring the global sx and was able to upgrade and give more testing to 0.5.0 in the coming days. I will try to also track down one by one the issues to eventually remove the global sx. |
Since upgrading 0.5.0-alpha.1, I see this error on external(non-theme-ui) components
example:
https://github.com/ccontrols/component-controls/blob/0335fb94440b8dc67a4b00c7db0560a2f42947aa/ui/components/src/CopyContainer/CopyContainer.tsx#L30
The text was updated successfully, but these errors were encountered: