Skip to content

With forwardRef Union types get lost #883

@bmsuseluda

Description

@bmsuseluda

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions