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

With forwardRef Union types get lost #883

Closed
bmsuseluda opened this issue Dec 19, 2023 · 1 comment
Closed

With forwardRef Union types get lost #883

bmsuseluda opened this issue Dec 19, 2023 · 1 comment

Comments

@bmsuseluda
Copy link

Hello together,

with the following usage of forwardRef union types get lost:

interface Props {
  /** The name to greet */
  name: "world" | "hello";
  title: string;
}

/**
 * Hello world component
 */
const MyComponent = forwardRef<ElementRef<"div">, Props>(
  ({name = 'world'}, ref) => {
    return <div />;
  }
);

A workaround is to add the type "Props to the spread as well:

interface Props {
  /** The name to greet */
  name: "world" | "hello";
  title: string;
}

/**
 * Hello world component
 */
const MyComponent = forwardRef<ElementRef<"div">, Props>(
  ({name = 'world'}: Props, ref) => {
    return <div />;
  }
);

But this is redundant because the type is already defined as a generic at the forwardRef function.

Would it be possible to support the generics of forwardRef?

Thanks in regards

@danez
Copy link
Collaborator

danez commented Dec 20, 2023

Duplicate of #878

@danez danez marked this as a duplicate of #878 Dec 20, 2023
@danez danez closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants