From 036776884cdd1c6b7f2e775d1397cecc86714393 Mon Sep 17 00:00:00 2001 From: Joseph Chamochumbi Date: Mon, 30 Sep 2024 10:09:52 +0200 Subject: [PATCH 1/2] fix: Do not omit alt on getImgProps return type, ImgProps --- packages/next/src/shared/lib/get-img-props.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/shared/lib/get-img-props.ts b/packages/next/src/shared/lib/get-img-props.ts index 157dfa16e54c7..4df01b8911577 100644 --- a/packages/next/src/shared/lib/get-img-props.ts +++ b/packages/next/src/shared/lib/get-img-props.ts @@ -69,7 +69,7 @@ export type ImageProps = Omit< lazyRoot?: string } -export type ImgProps = Omit & { +export type ImgProps = Omit & { loading: LoadingValue width: number | undefined height: number | undefined From 093283c70d8c5c4aeb2d8b4b266c3779f0d7bdab Mon Sep 17 00:00:00 2001 From: Joseph Chamochumbi Date: Wed, 2 Oct 2024 21:46:28 +0200 Subject: [PATCH 2/2] test: Assert type of props returned from `getImageProps` --- test/unit/next-image-get-img-props.test.ts | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/unit/next-image-get-img-props.test.ts b/test/unit/next-image-get-img-props.test.ts index 19a2e4125ba82..6ae0eb35f773b 100644 --- a/test/unit/next-image-get-img-props.test.ts +++ b/test/unit/next-image-get-img-props.test.ts @@ -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',