Skip to content

Commit bb3f580

Browse files
styfleicyJoseph
andauthored
fix: Do not omit alt on getImgProps return type, ImgProps (#70818)
- Backport #70608 to `14.2.x` Co-authored-by: Joseph <sephxd1234@gmail.com>
1 parent cb8113b commit bb3f580

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/next/src/shared/lib/get-img-props.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type ImageProps = Omit<
6767
lazyRoot?: string
6868
}
6969

70-
export type ImgProps = Omit<ImageProps, 'src' | 'alt' | 'loader'> & {
70+
export type ImgProps = Omit<ImageProps, 'src' | 'loader'> & {
7171
loading: LoadingValue
7272
width: number | undefined
7373
height: number | undefined

test/unit/next-image-get-img-props.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,30 @@ describe('getImageProps()', () => {
3737
['src', '/_next/image?url=%2Ftest.png&w=256&q=75'],
3838
])
3939
})
40+
41+
it('should have correct type for props', async () => {
42+
const { props } = getImageProps({
43+
alt: 'a nice desc',
44+
id: 'my-image',
45+
src: '/test.png',
46+
width: 100,
47+
height: 200,
48+
})
49+
50+
expect(props.alt).toBeString()
51+
expect(props.id).toBeString()
52+
expect(props.loading).toBeString()
53+
54+
expect(props.width).toBeNumber()
55+
expect(props.height).toBeNumber()
56+
57+
expect(props.decoding).toBeString()
58+
expect(props.style).toBeObject()
59+
expect(props.style.color).toBeString()
60+
expect(props.src).toBeString()
61+
expect(props.srcSet).toBeString()
62+
})
63+
4064
it('should handle priority', async () => {
4165
const { props } = getImageProps({
4266
alt: 'a nice desc',

0 commit comments

Comments
 (0)