From 95b5f6280d124f8d6f866dc3286406c272ee91bf Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:39:21 +0200 Subject: [PATCH] fix(assets): Fix misc types issues (#8568) * fix(assets): Fix misc types issues * fix: remove unnecessary change * chore: changeset --- .changeset/fair-teachers-protect.md | 5 +++++ packages/astro/client.d.ts | 4 +--- packages/astro/content-types.template.d.ts | 1 + packages/astro/src/@types/astro.ts | 1 + packages/astro/src/assets/internal.ts | 2 +- packages/astro/src/assets/types.ts | 5 ++++- 6 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 .changeset/fair-teachers-protect.md diff --git a/.changeset/fair-teachers-protect.md b/.changeset/fair-teachers-protect.md new file mode 100644 index 000000000..df8215b9f --- /dev/null +++ b/.changeset/fair-teachers-protect.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix small types issues related to `astro:assets`'s AVIF support and `getImage` diff --git a/packages/astro/client.d.ts b/packages/astro/client.d.ts index 146ab8355..5f396b522 100644 --- a/packages/astro/client.d.ts +++ b/packages/astro/client.d.ts @@ -48,9 +48,7 @@ declare module 'astro:assets' { * This is functionally equivalent to using the `` component, as the component calls this function internally. */ getImage: ( - options: - | import('./dist/assets/types.js').ImageTransform - | import('./dist/assets/types.js').UnresolvedImageTransform + options: import('./dist/assets/types.js').UnresolvedImageTransform ) => Promise; imageConfig: import('./dist/@types/astro.js').AstroConfig['image']; getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService; diff --git a/packages/astro/content-types.template.d.ts b/packages/astro/content-types.template.d.ts index eb560193d..4d59d140f 100644 --- a/packages/astro/content-types.template.d.ts +++ b/packages/astro/content-types.template.d.ts @@ -33,6 +33,7 @@ declare module 'astro:content' { import('astro/zod').ZodLiteral<'webp'>, import('astro/zod').ZodLiteral<'gif'>, import('astro/zod').ZodLiteral<'svg'>, + import('astro/zod').ZodLiteral<'avif'>, ] >; }>; diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index 10e15b6ff..109629428 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -48,6 +48,7 @@ export type { ImageQuality, ImageQualityPreset, ImageTransform, + UnresolvedImageTransform, } from '../assets/types.js'; export type { RemotePattern } from '../assets/utils/remotePattern.js'; export type { SSRManifest } from '../core/app/types.js'; diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 9d2c9eb0e..f6c3b0b52 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -67,7 +67,7 @@ export async function getConfiguredImageService(): Promise { } export async function getImage( - options: ImageTransform | UnresolvedImageTransform, + options: UnresolvedImageTransform, imageConfig: AstroConfig['image'] ): Promise { if (!options || typeof options !== 'object') { diff --git a/packages/astro/src/assets/types.ts b/packages/astro/src/assets/types.ts index 0bf740d57..1712cda1c 100644 --- a/packages/astro/src/assets/types.ts +++ b/packages/astro/src/assets/types.ts @@ -28,8 +28,11 @@ export interface ImageMetadata { orientation?: number; } +/** + * A yet to be resolved image transform. Used by `getImage` + */ export type UnresolvedImageTransform = Omit & { - src: Promise<{ default: ImageMetadata }>; + src: ImageMetadata | string | Promise<{ default: ImageMetadata }>; }; /**