Skip to content

Support composition with any component, not just the ones created with tw #94

@jahirfiquitiva

Description

@jahirfiquitiva

I would like this library to support styling any component and not just the ones created with tw

I have tried styling 2 pre-built components from Next without success.

1. Image

Shot 2023-04-10 at 16 58 38@2x

Shot 2023-04-10 at 16 58 55@2x

As you can see, it does not recognize the Image properties as valid

2. Link with the styles of a Button

Having created a StyledButton component with tw (const StyledButton = tw.button), I want a Link component to look like that StyledButton

Shot 2023-04-10 at 17 21 05@2x

Shot 2023-04-10 at 17 55 12@2x

The whole error reads:

const otherProps: {
    title: string;
    openInNewTab?: boolean | undefined;
    download?: any;
    hrefLang?: string | undefined;
    media?: string | undefined;
    ping?: string | undefined;
    target?: HTMLAttributeAnchorTarget | undefined;
    ... 273 more ...;
    key?: Key | ... 1 more ... | undefined;
}
No overload matches this call.
  Overload 1 of 2, '(props: { onMouseEnter?: MouseEventHandler<HTMLButtonElement> | undefined; onTouchStart?: TouchEventHandler<HTMLButtonElement> | undefined; ... 272 more ...; $outlined?: boolean | undefined; } & { ...; }): ReactElement<...>', gave the following error.
    Type '(props: LinkProps) => JSX.Element' is not assignable to type 'undefined'.
  Overload 2 of 2, '(props: TailwindComponentPropsWith$As<DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, { ...; }, (props: LinkProps) => Element, LinkProps>): ReactElement<...>', gave the following error.
    Type '{ title: string; openInNewTab?: boolean | undefined; download?: any; hrefLang?: string | undefined; media?: string | undefined; ping?: string | undefined; target?: HTMLAttributeAnchorTarget | undefined; ... 275 more ...; $outlined: boolean | undefined; }' is not assignable to type 'ClassAttributes<HTMLButtonElement>'.
      Types of property 'ref' are incompatible.
        Type 'Ref<HTMLAnchorElement> | undefined' is not assignable to type 'LegacyRef<HTMLButtonElement> | undefined'.
          Type '(instance: HTMLAnchorElement | null) => void' is not assignable to type 'LegacyRef<HTMLButtonElement> | undefined'.
            Type '(instance: HTMLAnchorElement | null) => void' is not assignable to type '(instance: HTMLButtonElement | null) => void'.
              Types of parameters 'instance' and 'instance' are incompatible.
                Type 'HTMLButtonElement | null' is not assignable to type 'HTMLAnchorElement | null'.
                  Type 'HTMLButtonElement' is missing the following properties from type 'HTMLAnchorElement': charset, coords, download, hreflang, and 19 more.ts(2769)
tailwind.d.ts(51, 9): The expected type comes from property '$as' which is declared here on type 'IntrinsicAttributes & { onMouseEnter?: MouseEventHandler<HTMLButtonElement> | undefined; onTouchStart?: TouchEventHandler<HTMLButtonElement> | undefined; ... 272 more ...; $outlined?: boolean | undefined; } & { ...; }'

Basically it is expecting otherProps to be of the type of props for StyledButton, even when I have set it to render $as={Link} and therefore should work with Link props

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions