getImageProps and alt text #70443
-
SummaryI've created a picture element using getImageProps from next/image. But Im a bit confused about the type setup around alt text. I can pass my alt text to getImageProps along with the rest of the props. And when I destructure the result into ...rest, it contains the alt text I passed in. But when I spread ...rest on Image (the img tag) then typescript complains that alt is missing. So I guess Im asking why alt is omitted here: I mean I can just pass it again to the Image component, but why? Additional informationNo response Example
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Interesting... the As you point out, Since they have this explicit type check, for const props: ImgProps = {
...rest,
loading: isLazy ? 'lazy' : loading,
fetchPriority,
width: widthInt,
height: heightInt,
decoding,
className,
style: { ...imgStyle, ...placeholderStyle },
sizes: imgAttributes.sizes,
srcSet: imgAttributes.srcSet,
src: overrideSrc || imgAttributes.src,
} Accidentally removing |
Beta Was this translation helpful? Give feedback.
Interesting... the
getImageProps
function, does pick some properties from the arguments passed to it, and it justechoes
the rest.As you point out,
alt
, doesn't really have to be removed from the typing of whatgetImageProps
returns though. It is required to pass it, and it will be echo'ed out.Since they have this explicit type check, for
ImgProps
:Accidenta…