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

UseLinkReactProps typed incorrectly #3566

Open
brandongit2 opened this issue Feb 25, 2025 · 0 comments
Open

UseLinkReactProps typed incorrectly #3566

brandongit2 opened this issue Feb 25, 2025 · 0 comments
Assignees
Labels
types Changes to the typescript types

Comments

@brandongit2
Copy link

Which project does this relate to?

Router

Describe the bug

From your source code:

type UseLinkReactProps<TComp> = TComp extends keyof React.JSX.IntrinsicElements
  ? React.JSX.IntrinsicElements[TComp]
  : React.PropsWithoutRef<
      TComp extends React.ComponentType<infer TProps> ? TProps : never
    > &
      React.RefAttributes<
        TComp extends
          | React.FC<{ ref: infer TRef }>
          | React.Component<{ ref: infer TRef }>
          ? TRef
          : never
      >

Notice how you pull out TRef from the props of TComp. TRef would usually be of type Ref<...>. Then you wrap that in React.RefAttributes, which itself wraps the ref in Ref, leading to:

type Props = ... & {
  ref?: Ref<Ref<...>> | undefined;
}

And that double-wrapping leads to type errors.

Your Example Website or App

https://stackblitz.com/edit/github-dhwbicy7?file=src%2Ftypes.tsx

Steps to Reproduce the Bug or Issue

Check out the type error in types.tsx.

Expected behavior

Expected to be able to pass in const ref: Ref<HTMLAnchorElement> without an error

Screenshots or Videos

No response

Platform

[N/A]

Additional context

No response

@SeanCassiere SeanCassiere added the types Changes to the typescript types label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types Changes to the typescript types
Projects
None yet
Development

No branches or pull requests

3 participants