Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not omit alt on getImgProps return type, ImgProps (#70608)
### What? Small type tweak, asked for in #70443 ### Why? The `alt` prop is required on the call to `getImgProps`, and the implementation, returns it back to the caller, however, the type signature of the return type for `getImgProps`, omits the `alt` prop, which means that users have to manually apply the `alt` prop. That is to say, that in this example, tweaked from the docs: ```jsx import { getImageProps } from 'next/image' export default function Page() { const common = { alt: 'Theme Example', width: 800, height: 400 } const { props: { srcSet: dark }, } = getImageProps({ ...common, src: '/dark.png' }) const { props: { srcSet: light, ...rest }, } = getImageProps({ ...common, src: '/light.png' }) return ( <picture> <source media="(prefers-color-scheme: dark)" srcSet={dark} /> <source media="(prefers-color-scheme: light)" srcSet={light} /> {/* the alt prop is here, but as far as TypeScript is concerned, it is not */} <SomeCustomImageComponent {...rest} /> </picture> ) } ``` So users have to do: ```jsx <SomeCustomImageComponent {...rest} alt={common.alt} /> ``` See more at, #70443 ### How? Remove `alt` from the Omit union. ```tsx export type ImgProps = Omit<ImageProps, 'src' | 'alt' | 'loader'> & { /* other stuff */ } ``` Fixes #70443
- Loading branch information