prismic-react icon indicating copy to clipboard operation
prismic-react copied to clipboard

internalComponent has confusing type errors

Open AO19 opened this issue 1 year ago • 3 comments

Versions

  • @prismicio/client: 7.16.0,
  • @prismicio/helpers: 2.3.9,
  • @prismicio/next: 2.0.0,
  • @prismicio/react: 3.0.0,
  • @prismicio/slice-simulator-react: 0.2.3,
  • react: 19.0.0
  • next: 15.1.7
  • Node.js: v22.12.0

Reproduction

Additional Details
import {
  PrismicLink as BasePrismicLink,
  LinkProps,
  PrismicLinkProps,
} from '@prismicio/react';
import Link from 'next/link';
import { linkResolver } from 'prismicio';

function InternalLink(props: LinkProps) {
  return <Link {...props} />;
}

export function PrismicLink(props: PrismicLinkProps) {
  return (
    <BasePrismicLink
      linkResolver={linkResolver}
      internalComponent={InternalLink}
      {...props}
    />
  );
}

Steps to reproduce

I followed this guide in my Next.js (Pages Router) app. Very confusing to be honest.

What is expected?

PrismicLink accepts InternalLink (Next Link component).

What is actually happening?

Type '(props: LinkProps) => Element' is not assignable to type 'ElementType<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>> | undefined'.
  Type '(props: LinkProps) => Element' is not assignable to type 'FunctionComponent<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>>'.
    Types of parameters 'props' and 'props' are incompatible.
      Type 'DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>' is not assignable to type 'LinkProps'.
        Types of property 'href' are incompatible.
          Type 'string | undefined' is not assignable to type 'string'.
            Type 'undefined' is not assignable to type 'string'.ts(2322)
PrismicLink.d.ts(45, 5): The expected type comes from property 'internalComponent' which is declared here on type 'IntrinsicAttributes & (PrismicLinkProps<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, DetailedHTMLProps<...>> & { ...; })'

AO19 avatar Feb 13 '25 13:02 AO19