I have a functional React component that wraps an image element:
type BlobImageProps = HTMLAttributes<HTMLImageElement> & {
blobId: string
}
function BlobImage(props: BlobImageProps){
const {blobId, ...htmlAttributes} = props
const [objectUrl, setObjectUrl] = useState<string>()
// ...
// ... load image blob using effect hook
// ...
return <img {...htmlAttributes} src={objectUrl}/>
}
And I use it like this:
function MyPage(){
//...
return (
<BlobImage blobId="xyz1234" alt="Funny cats"/>
)
}
However, I get a typeScript error saying
Type '{ blobId: string; alt: string; }' is not assignable to type 'IntrinsicAttributes & HTMLAttributes<HTMLImageElement> & { blobId: string; }'.
Property 'alt' does not exist on type 'IntrinsicAttributes & HTMLAttributes<HTMLImageElement> & { blobId: string; }'.
What's wrong with my typing? What type should BlobImageProps have?