Skip to content

Commit 60b14ff

Browse files
authored
Fix type error when using content collection images after apng support (#17783)
* fix(content): add apng to the image() schema format union `apng` was added to VALID_INPUT_FORMATS in #17774, but the ImageFunction type in content/config.ts was not updated to match, so passing an image from a collection schema to a component failed to type-check. Add a type test asserting the schema's format union matches ImageInputFormat, and widen the check workflow's path filter so changes under packages/astro/src and the shipped .d.ts files run the examples check before merge. * revert: keep astro check path filter as-is
1 parent 3578d45 commit 60b14ff

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎.changeset/gold-bugs-glow.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fixes a type error when passing an image from a content collection `image()` schema to a component or `<Image />`. The schema returned by `image()` was missing the `apng` format, so it no longer matched the type of an imported image.

‎packages/astro/src/content/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ImageFunction = () => z.ZodObject<{
3939
zCore.$ZodLiteral<'gif'>,
4040
zCore.$ZodLiteral<'svg'>,
4141
zCore.$ZodLiteral<'avif'>,
42+
zCore.$ZodLiteral<'apng'>,
4243
]
4344
>;
4445
}>;

‎packages/astro/test/types/schemas.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type { SessionDriverConfigSchema } from '../../dist/core/session/config.j
99
import type { SessionDriverConfig } from '../../dist/core/session/types.js';
1010
import type { SvgOptimizer } from '../../dist/assets/svg/types.js';
1111
import type { SvgOptimizerSchema } from '../../dist/assets/svg/config.js';
12+
import type { ImageInputFormat } from '../../dist/assets/types.js';
13+
import type { SchemaContext } from '../../dist/content/config.js';
1214

1315
describe('fonts', () => {
1416
it('FontFamily type matches FontFamilySchema', () => {
@@ -44,3 +46,10 @@ describe('svgOptimizer', () => {
4446
expectTypeOf<z.input<typeof SvgOptimizerSchema>>().toEqualTypeOf<SvgOptimizer>();
4547
});
4648
});
49+
50+
describe('content image()', () => {
51+
it('image() schema format matches ImageInputFormat', () => {
52+
type ImageSchema = ReturnType<SchemaContext['image']>;
53+
expectTypeOf<z.output<ImageSchema>['format']>().toEqualTypeOf<ImageInputFormat>();
54+
});
55+
});

0 commit comments

Comments
 (0)