Skip to content
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

IconProps type is incompatible with icons components #1077

Closed
rtivital opened this issue Apr 2, 2024 · 3 comments · Fixed by #1078
Closed

IconProps type is incompatible with icons components #1077

rtivital opened this issue Apr 2, 2024 · 3 comments · Fixed by #1078
Labels
bug Something isn't working pull-request Pull request available

Comments

@rtivital
Copy link

rtivital commented Apr 2, 2024

The following code will have a TypeScript error:

import { IconCreditCard, IconProps } from "@tabler/icons-react";

// Error about incompatible `ref` prop
function TestIcon(props: IconProps) {
  return <IconCreditCard {...props} />;
}

Sandbox with a reproduction – https://codesandbox.io/p/sandbox/mantine-react-template-forked-jhy3jl?file=%2Fsrc%2FApp.tsx%3A3%2C1-7%2C2

The error is gone once ref prop is removed:

// ok
function TestIcon(props: Omit<IconProps, 'ref'>) {
  return <IconCreditCard {...props} />;
}

To fix types mismatch change IconProps type from

interface IconProps extends Partial<Omit<React.SVGProps<SVGSVGElement>, 'stroke'>> {
    size?: string | number;
    stroke?: string | number;
}

to

interface IconProps extends Partial<Omit<React.ComponentPropsWithoutRef<'svg'>, 'stroke'>> {
  size?: string | number;
  stroke?: string | number;
}
@diego-menezes
Copy link

i cant't use newer version becasue this bug...

@diego-menezes
Copy link

@rtivital you know a workarround for this?

@diego-menezes
Copy link

the solution for me

in 2.x i use

export interface Acao {
...
    icone: (props: TablerIconsProps) => ReactElement;
...
}

now in 3.2.0

export interface Acao {

    icone: React.ExoticComponent<React.RefAttributes<Icon>>;

}

and where i used Icon in props needs no changes.

export const menu: Acao[] = [
  {
...
    icone: IconDashboard,
...
  },
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pull-request Pull request available
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants