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

typescript error caused by src/utils/forwardRef.tsx when running tsc #4609

Open
GamerGirlandCo opened this issue Jan 21, 2025 · 1 comment
Open
Labels

Comments

@GamerGirlandCo
Copy link

Current behaviour

node_modules/react-native-paper/src/utils/forwardRef.tsx:21:14 - error TS2322: Type '<T, P = {}>(render: ForwardRefRenderFunction<T, PropsWithoutRef<P>>) => ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>>' is not assignable to type '<T, P = {}>(render: ForwardRefRenderFunction<T, P>) => ForwardRefComponent<T, P>'.
  Types of parameters 'render' and 'render' are incompatible.
    Type 'ForwardRefRenderFunction<T, P>' is not assignable to type 'ForwardRefRenderFunction<T, PropsWithoutRef<P>>'.
      Types of parameters 'props' and 'props' are incompatible.
        Type 'PropsWithoutRef<P>' is not assignable to type 'P'.
          'P' could be instantiated with an arbitrary type which could be unrelated to 'PropsWithoutRef<P>'.

Expected behaviour

type checking should complete without errors

How to reproduce?

  1. clone/download https://snack.expo.dev/@the-tablet/6dd396
  2. run tsc --noEmit in the project directory

Preview

N/A

What have you tried so far?

  1. redeclaring typescript module react-native-paper/src/utils/forwardRef.tsx
import 'react-native-paper/src/utils/forwardRef';
declare module 'react-native-paper/src/utils/forwardRef' {
  export declare const forwardRef: <T, P = {}>(
    render: ForwardRefRenderFunction<T, PropsWithoutRef<P>>
  ) => ForwardRefComponent<T, P> = React.forwardRef;
}
  1. adding skipLibCheck: true to tsconfig.json
  2. explicitly adding node_modules/react-native-paper/src to the exclude array in tsconfig.json
  3. upgrading react-native-paper to the latest version

Your Environment

software version
ios n/a
android 35
react-native 0.76.6
react-native-paper 5.13.1
node 22.12.0
npm or yarn yarn 1.22.22
expo sdk N/A
@GamerGirlandCo
Copy link
Author

fwiw, the fix is simple:

 export const forwardRef: <T, P = {}>(
-  render: ForwardRefRenderFunction<T, P>
+  render: ForwardRefRenderFunction<T, PropsWithoutRef<P>>
 ) => ForwardRefComponent<T, P> = React.forwardRef;

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

No branches or pull requests

1 participant