prismicio / prismic-react

React components and hooks to fetch and present Prismic content
https://prismic.io/docs/technologies/homepage-reactjs
Apache License 2.0
153 stars 40 forks source link

Incorrect types for custom link components in `PrismicRichText` #173

Open thompsongl opened 1 year ago

thompsongl commented 1 year ago

Versions

Reproduction

https://codesandbox.io/s/modern-shadow-2tqpqb?file=/src/App.tsx

Steps to reproduce

1) Go to the repro link 2) See the TypeScript errors 3) Change the @prismicio/react version to v2.1.2 4) See the TypeScript errors disappear

What is expected?

@prismicio/react@2.5.1 should not have the type errors

What is actually happening?

Trying to upgrade @prismicio/react to the latest version is blocked on type errors related to internalLinkComponent and externalLinkComponent:

Type '({ href, target, children, rel }: { href: any; target: any; children: any; rel: any; }) => Element' is not assignable to type '"a"'.

I have not been able to find a workaround (aside from type casting) or update to the PrismicLinkProps interface that accommodates custom components and DOM tag names.

lihbr commented 1 year ago

Hey there, thanks for submitting an issue with a comprehensive reproduction!

I managed to reproduce and narrow the problematic version to version 2.3.0, see: https://github.com/prismicio/prismic-react/pull/146

Remarks: In the reproduction, 2 TypeScript versions are installed: 4.9.5 and 4.1.3, the latter being 2+ years old. However, it looks like it wasn't the one picked up, not impacting the reproduction. I reproduced the issue again with TypeScript 4.8.4 and 4.7.4.

We'll publish a fix soon ☺️