react-pdf icon indicating copy to clipboard operation
react-pdf copied to clipboard

Presentation attributes in Svg tag show TS error

Open rubenvar opened this issue 2 years ago • 0 comments

Describe the bug

In a TS project, when defining any presentation attribute in a <Svg> element, I get the following TS error:

(JSX attribute) strokeWidth: string
No overload matches this call.
  Overload 1 of 2, '(props: SVGProps | Readonly<SVGProps>): Svg', gave the following error.
    Type '{ children: Element[]; width: number; height: number; viewBox: string; strokeWidth: string; strokeLinecap: string; strokeLinejoin: string; style: { marginRight: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<SVGProps> & Readonly<{ children?: ReactNode; }>'.
      Property 'strokeWidth' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<SVGProps> & Readonly<{ children?: ReactNode; }>'.
  Overload 2 of 2, '(props: SVGProps, context: any): Svg', gave the following error.
    Type '{ children: Element[]; width: number; height: number; viewBox: string; strokeWidth: string; strokeLinecap: string; strokeLinejoin: string; style: { marginRight: number; }; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<SVGProps> & Readonly<{ children?: ReactNode; }>'.
      Property 'strokeWidth' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<SVGProps> & Readonly<{ children?: ReactNode; }>'.ts(2769)

The svg is rendered correctly.

To Reproduce

  1. Use a presentation attribute in a <Svg> tag, ie. <Svg strokeWidth={2}>...</Svg>.
  2. See the TS error.

See the reproduction in a TS codesandbox project. Note that the small svg icon is rendered correctly.

Expected behavior

It shouldn't show a TS error in these (as per the docs) allowed attributes.

Desktop (please complete the following information):

  • I see the error in my VSCode (1.67.2) editor (in MacOS 11.6.6), as well as in codesandbox online.
  • React-pdf 2.1.1

rubenvar avatar Jun 07 '22 10:06 rubenvar