Skip to content

memo breaks the typing #9

@Noitidart

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.

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