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

Presentation attributes in Svg tag show TS error #1873

Closed
rubenvar opened this issue Jun 7, 2022 · 8 comments · Fixed by #2363
Closed

Presentation attributes in Svg tag show TS error #1873

rubenvar opened this issue Jun 7, 2022 · 8 comments · Fixed by #2363

Comments

@rubenvar
Copy link

rubenvar commented Jun 7, 2022

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
@papack
Copy link

papack commented Nov 11, 2022

i create a Pullrequest with a Solution in #2082

@papack
Copy link

papack commented Jan 31, 2023

INFO: this issue should be solved see PR #1798

@jeetiss
Copy link
Collaborator

jeetiss commented Jan 31, 2023

@papack can i close this issue then?

@papack
Copy link

papack commented Jan 31, 2023

@jeetiss my problem is fixed. this bug should also be fixed with it. i found this ticket via google when i had the problem. In my opinion it can be closed. But i am not the ticket creator or a maintainer. if i was a maintainer i would close it and ask @rubenvar to open it again if his problem still exists :)

@jeetiss jeetiss closed this as completed Jan 31, 2023
@rubenvar
Copy link
Author

rubenvar commented Feb 9, 2023

I can't re-open the issue, but the issue still exists. Please check the basic reproduction in codesandbox.

After updating @react-pdf/renderer to the last version (3.1.3) I get the following TS error when using valid presentation attributes:

No overload matches this call.
  Overload 1 of 2, '(props: PropsWithChildren<SVGProps> | Readonly<PropsWithChildren<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<PropsWithChildren<SVGProps>> & Readonly<...>'.
      Property 'strokeWidth' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<PropsWithChildren<SVGProps>> & Readonly<...>'.
  Overload 2 of 2, '(props: PropsWithChildren<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<PropsWithChildren<SVGProps>> & Readonly<...>'.
      Property 'strokeWidth' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Svg> & Readonly<PropsWithChildren<SVGProps>> & Readonly<...>'.ts(2769)

@jeetiss jeetiss reopened this Feb 9, 2023
@rubenvar
Copy link
Author

Ok, I found out that adding the presentation attributes in the SVGProps interface declaration here would solve the issue:

interface SVGProps extends NodeProps {
  /**
  * Enables debug mode on page bounding box.
  * @see https://react-pdf.org/advanced#debugging
  */
  debug?: boolean;
  width?: string | number;
  height?: string | number;
  viewBox?: string;
  preserveAspectRatio?: string;
+ strokeWidth?: string;
}

Of course adding just one changes the TS error to show on the next attribute. All the valid attributes (as per the docs) should be added I guess.

Would this be the right way to do it? I can try to send a PR if it will help :)

@jeetiss
Copy link
Collaborator

jeetiss commented Feb 21, 2023

Sounds like a great plan! I will merge it

@TheMikeyRoss
Copy link
Contributor

image
strokeLinejoin works but throws a TS warning

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

Successfully merging a pull request may close this issue.

5 participants