diff --git a/.changeset/nice-jars-breathe.md b/.changeset/nice-jars-breathe.md new file mode 100644 index 000000000000..1a47e9bc3c33 --- /dev/null +++ b/.changeset/nice-jars-breathe.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix getImage type diff --git a/packages/astro/client-base.d.ts b/packages/astro/client-base.d.ts index 52bd5870fc77..15c1fb905420 100644 --- a/packages/astro/client-base.d.ts +++ b/packages/astro/client-base.d.ts @@ -3,7 +3,26 @@ declare module 'astro:assets' { // Exporting things one by one is a bit cumbersome, not sure if there's a better way - erika, 2023-02-03 type AstroAssets = { - getImage: typeof import('./dist/assets/index.js').getImage; + // getImage's type here is different from the internal function since the Vite module implicitly pass the service config + /** + * Get an optimized image and the necessary attributes to render it. + * + * **Example** + * ```astro + * --- + * import { getImage } from 'astro:assets'; + * import originalImage from '../assets/image.png'; + * + * const optimizedImage = await getImage({src: originalImage, width: 1280 }); + * --- + * + * ``` + * + * This is functionally equivalent to using the `` component, as the component calls this function internally. + */ + getImage: ( + options: import('./dist/assets/types.js').ImageTransform + ) => Promise; getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService; Image: typeof import('./components/Image.astro').default; }; diff --git a/packages/astro/src/assets/internal.ts b/packages/astro/src/assets/internal.ts index 945b5a3e862d..c4b8ca751eb9 100644 --- a/packages/astro/src/assets/internal.ts +++ b/packages/astro/src/assets/internal.ts @@ -29,22 +29,6 @@ export async function getConfiguredImageService(): Promise { return globalThis.astroAsset.imageService; } -/** - * Get an optimized image and the necessary attributes to render it. - * - * **Example** - * ```astro - * --- - * import { getImage } from 'astro:assets'; - * import originalImage from '../assets/image.png'; - * - * const optimizedImage = await getImage({src: originalImage, width: 1280 }); - * --- - * - * ``` - * - * This is functionally equivalent to using the `` component, as the component calls this function internally. - */ export async function getImage( options: ImageTransform, serviceConfig: Record