Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Do not omit alt on getImgProps return type, ImgProps #70608

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -69,7 +69,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
Loading