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

ForwardedRef not assignable to ref type #2753

Open
jeremy-flusin opened this issue Jan 25, 2024 · 0 comments
Open

ForwardedRef not assignable to ref type #2753

jeremy-flusin opened this issue Jan 25, 2024 · 0 comments

Comments

@jeremy-flusin
Copy link

Issue description

Hi there,

When trying to use a forwarded ref with the component, I encountered the following TypeScript error:

TS2769: No overload matches this call.

Overload  1  of  2 ,  (props: Props | Readonly<Props>): ReactSVG , gave the following error.
Type  ForwardedRef<HTMLDivElement>  is not assignable to type
((string | ((instance: ReactSVG | null) => void) | RefObject<ReactSVG>) & ((string | ((instance: HTMLWrapperType | null) => void) | RefObject<...>) & (string | ... 1 more ... | RefObject<...>))) | null | undefined

Overload  2  of  2 ,  (props: Props, context: any): ReactSVG , gave the following error.
Type  ForwardedRef<HTMLDivElement>  is not assignable to type
((string | ((instance: ReactSVG | null) => void) | RefObject<ReactSVG>) & ((string | ((instance: HTMLWrapperType | null) => void) | RefObject<...>) & (string | ... 1 more ... | RefObject<...>))) | null | undefined

Reproducer

I've created a CodeSandbox demonstrating the issue.

Attemped workaround

I tried to change the ForwardedRef type to HTMLDivElement, HTMLSpanElement or SVGSVGElement with no success.
With type assertion ref={ref as any} compilation works fine, and the runtime behaviour is as expected.

Thank you for your time and attention to this matter.

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

No branches or pull requests

1 participant