N
N
nskaskyo2021-08-14 14:27:19
typescript
nskaskyo, 2021-08-14 14:27:19

How is a tag typed in React on typescropt?

Good day.

The HTMLLinkElement type contains href: string but when destructuring the props it says:
Property "href" does not exist in the type "ILinkProps & { children?: ReactNode; }".ts(2339)

Tell me where is it wrong?
Thanks

interface ILinkProps
  extends DetailedHTMLProps<HTMLAttributes<HTMLLinkElement>, HTMLLinkElement> {
  cursorPointer?: boolean;
}

export const Link: React.FC<ILinkProps> = (props): JSX.Element => {
  const { innerElement, cursorPointer = false, children, href } = props;
  return <a>{children}</a>
  );
};


Here is the interface code before href from lib.dom.d.ts
interface HTMLLinkElement extends HTMLElement, LinkStyle {
    as: string;
    /**
     * Sets or retrieves the character set used to encode the object.
     */
    /** @deprecated */
    charset: string;
    crossOrigin: string | null;
    disabled: boolean;
    /**
     * Sets or retrieves a destination URL or an anchor point.
     */
    href: string;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-08-14
@Azurre

I usually do this:

interface ILinkProps extends React.HTMLProps<HTMLLinkElement> {
  cursorPointer?: boolean;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question