react-native-htmlview icon indicating copy to clipboard operation
react-native-htmlview copied to clipboard

Property 'refs' is missing in type 'Component<HTMLViewProps, any, any>' but required in type 'Component<any, any, any>'.

Open Legend999 opened this issue 9 months ago • 0 comments

When trying to use the HTMLView component, TypeScript throws the following error:

TS2786: 'HTMLView' cannot be used as a JSX component.
  Its type 'ComponentType<HTMLViewProps>' is not a valid JSX element type.
    Type 'ComponentClass<HTMLViewProps, any>' is not assignable to type 'ElementType'.
      Type 'ComponentClass<HTMLViewProps, any>' is not assignable to type 'new (props: any, deprecatedLegacyContext?: any) => Component<any, any, any>'.
        Property 'refs' is missing in type 'Component<HTMLViewProps, any, any>' but required in type 'Component<any, any, any>'.

55         <HTMLView
            ~~~~~~~~

  node_modules/@types/react/index.d.ts:1021:9
    1021         refs: {
                 ~~~~
    'refs' is declared here.

This issue is essentially the same as the one described in this discussion from another package: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/71404

A workaround was presented for pnpm by utilizing the overrides field. For yarn, you can achieve a similar fix by adding the same version of @types/react from your devDependencies to the resolutions field in your package.json:

  "resolutions": {
    "@types/react": "~18.2.45"
  }

Legend999 avatar Jan 07 '25 20:01 Legend999