Skip to content

memo breaks the typing #9

Open
Open

Description

@Noitidart

Thanks for this awesome article on logrocket.

I tried wrapping my component with memo, but it breaks the typing. Can you please advise?

import {
  memo, type ComponentPropsWithoutRef, type ElementType,
  type PropsWithChildren
} from 'react';


type TBadgeBaseProps<T extends ElementType> = PropsWithChildren<{
  as?: T;
  color: 'primary' | 'gray' | 'green' | 'red' | 'yellow' | 'blue' | 'orange';
}>;
type TBadgeProps<T extends ElementType> = TBadgeBaseProps<T> &
  Omit<ComponentPropsWithoutRef<T>, keyof TBadgeBaseProps<T>>;

const Badge = memo(function Badge<T extends ElementType = 'span'>({
  as,
  className,
  color,
  ...rest
}: TBadgeProps<T>) {
});

const test = <Badge href="foo">Hello</Badge>;

In the const test, it's not properly saying that href is not allowed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions