Skip to content

Commit

Permalink
fix: Do not omit alt on getImgProps return type, ImgProps (#70818)
Browse files Browse the repository at this point in the history
- Backport #70608 to `14.2.x`

Co-authored-by: Joseph <sephxd1234@gmail.com>
  • Loading branch information
styfle and icyJoseph authored Oct 6, 2024
1 parent cb8113b commit bb3f580
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/shared/lib/get-img-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type ImageProps = Omit<
lazyRoot?: string
}

export type ImgProps = Omit<ImageProps, 'src' | 'alt' | 'loader'> & {
export type ImgProps = Omit<ImageProps, 'src' | 'loader'> & {
loading: LoadingValue
width: number | undefined
height: number | undefined
Expand Down
24 changes: 24 additions & 0 deletions test/unit/next-image-get-img-props.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ describe('getImageProps()', () => {
['src', '/_next/image?url=%2Ftest.png&w=256&q=75'],
])
})

it('should have correct type for props', async () => {
const { props } = getImageProps({
alt: 'a nice desc',
id: 'my-image',
src: '/test.png',
width: 100,
height: 200,
})

expect(props.alt).toBeString()
expect(props.id).toBeString()
expect(props.loading).toBeString()

expect(props.width).toBeNumber()
expect(props.height).toBeNumber()

expect(props.decoding).toBeString()
expect(props.style).toBeObject()
expect(props.style.color).toBeString()
expect(props.src).toBeString()
expect(props.srcSet).toBeString()
})

it('should handle priority', async () => {
const { props } = getImageProps({
alt: 'a nice desc',
Expand Down

0 comments on commit bb3f580

Please sign in to comment.