Skip to content

styled(MantineButton) rejects all props in 6.4.2 (regression from 6.1.x) #5756

Closed

Description

@dennisoelkers

In 6.1.x, wrapping a component whose React.ComponentPropsWithRef<typeof T> resolves to {} produced a styled component that was permissive enough to accept arbitrary props at JSX call sites. In 6.4.2 the same code rejects every prop, including children.

This breaks every styled(X) where X is a Mantine v7 polymorphic-factory component (Button, Card, Menu.Item, Badge, SegmentedControl, …). TypeScript can't introspect Mantine's callable-generic intersection, so React.ComponentPropsWithRef<typeof X> resolves to {} in any sc version. 6.1.x stayed permissive on that empty BaseProps; 6.4.2 does not.

Simple Example

import * as React from 'react';
import styled from 'styled-components';
import { Button as MantineButton } from '@mantine/core';

const Styled = styled(MantineButton)`color: red;`;

// 6.1.x: OK
// 6.4.2: TS2769 — `variant` and `children` do not exist on
//   `FastOmit<FastOmit<{}, never> & Partial<Pick<{}, never>>, "as" | "forwardedAs">
//    & { as?: WebTarget; forwardedAs?: WebTarget }`
const usage = <Styled variant="filled">hi</Styled>;

Activity

  1. self-assigned this
    on May 30, 2026
  2. quantizor commented on Jun 2, 2026

    @quantizor
    Contributor

    Sorry for the trouble, could you try out #5759 in the form of [email protected] please?

  3. dennisoelkers commented on Jun 2, 2026

    @dennisoelkers
    Author

    Hey @quantizor!

    Thanks for the quick response/fix to this. Using 6.x-test fixes the minimal example that I provided, but unfortunately we still see issues when an additional/transient prop is added to the styled Mantine component like this:

      import { Button } from '@mantine/core';
      import styled from 'styled-components';
    
      const StyledWithExtras = styled(Button)<{ $variant: 'a' | 'b' }>`color: red;`;
      const x = <StyledWithExtras $variant="a" variant="filled">hi</StyledWithExtras>;
      // TS2769 — Property 'children' does not exist on type
      //   IntrinsicAttributes & FastOmit<FastOmit<FastOmit<{}, '$variant'> & { $variant: 'a' | 'b' }, never> & Partial<...>, ...>

    In this case, it is revealed that the internal type is still resolved as FastOmit. A fix for this would be great!

  4. kkwasny-rtbh commented on Jun 11, 2026

    @kkwasny-rtbh

    We're running into a similar problem with styled() wrapping a polymorphic/generic component.
    The wrapped component silently accepts props that the component itself would reject.

    Repro

    import * as React from "react";
    import styled from "styled-components";
    
    type AsProp<C extends React.ElementType> = { as?: C };
    type PolymorphicComponentProps<C extends React.ElementType, P = object> =
      React.PropsWithChildren<P & AsProp<C>> &
      Omit<React.ComponentPropsWithoutRef<C>, keyof (AsProp<C> & P)>;
    
    type ButtonVariant = "primary" | "secondary";
    
    interface ButtonBaseProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
      variant?: ButtonVariant;
    }
    
    type ButtonProps<C extends React.ElementType = "button"> =
      PolymorphicComponentProps<C, ButtonBaseProps>;
    
    const Button = <C extends React.ElementType = "button">(props: ButtonProps<C>) => null;
    
    const StyledButton = styled(Button)``;
    
    // Direct component correctly rejects the bad variant:
    const ok = <Button variant="totally-fake">x</Button>;          // errors (correct)
    
    // Wrapped component silently accepts it:
    const bad = <StyledButton variant="totally-fake">x</StyledButton>; // no error — expected an error

    On 6.4.x the StyledButton line produces no error, even though the direct Button usage does.
    Any help will be much appreciated!

  5. quantizor commented on Aug 6, 2026

    @quantizor
    Contributor

    There's a patch prerelease ([email protected]) that fixes a few other issues if you could test it and let me know if it fixes your issue?

  6. quantizor commented on Aug 6, 2026

    @quantizor
    Contributor

    Didn't mean to auto-close, waiting for your yay/nay.

  7. quantizor commented on Aug 7, 2026

    @quantizor
    Contributor
  8. kkwasny-rtbh commented on Aug 10, 2026

    @kkwasny-rtbh

    Hey @quantizor, thanks for your response!

    The problem I mentioned in my earlier comment still seems unresolved on 6.5.1 — using that repro, <StyledButton variant="totally-fake"> is still accepted silently, while the unwrapped <Button variant="totally-fake"> correctly errors.

    Could you take a look, or shall I report a separate issue?

  9. quantizor commented on Aug 10, 2026

    @quantizor
    Contributor

    Hey @quantizor, thanks for your response!

    The problem I mentioned in my earlier comment still seems unresolved on 6.5.1 — using that repro, <StyledButton variant="totally-fake"> is still accepted silently, while the unwrapped <Button variant="totally-fake"> correctly errors.

    Could you take a look, or shall I report a separate issue?

    Yes a new focused ticket would be helpful

  10. kkwasny-rtbh commented on Aug 11, 2026

    @kkwasny-rtbh

    @quantizor, thanks a lot for the quick response!

    The fix in 6.5.2-prerelease-20260810214005 seems to work fine so I'm looking forward to the release. 👍

  11. quantizor commented on Sep 25, 2026

    @quantizor
    Contributor

    Closing as fixed: the original case shipped in 6.5.1 and the follow-up case in 6.5.2. Please open a new issue if anything still looks off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions