From 03779ad9c620c5fb365d89a70fcad0399181e9f5 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 2 May 2023 11:36:48 +0200 Subject: [PATCH 1/3] fix(types): Fix getImage type requesting for a second parameter --- packages/astro/client-base.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/astro/client-base.d.ts b/packages/astro/client-base.d.ts index 52bd5870fc77..ef1b89dff588 100644 --- a/packages/astro/client-base.d.ts +++ b/packages/astro/client-base.d.ts @@ -3,7 +3,9 @@ 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: ( + options: import('./dist/assets/types.js').ImageTransform + ) => Promise; getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService; Image: typeof import('./components/Image.astro').default; }; From a8e5a52bd7bd5c677f680deaf52e1552b8d71d59 Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 2 May 2023 11:50:35 +0200 Subject: [PATCH 2/3] fix: move jsdoc comment for users --- packages/astro/client-base.d.ts | 17 +++++++++++++++++ packages/astro/src/assets/internal.ts | 16 ---------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/astro/client-base.d.ts b/packages/astro/client-base.d.ts index ef1b89dff588..15c1fb905420 100644 --- a/packages/astro/client-base.d.ts +++ b/packages/astro/client-base.d.ts @@ -3,6 +3,23 @@ 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'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; 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 From 4513f64bde764a37215229949f55b4528c74013f Mon Sep 17 00:00:00 2001 From: Princesseuh Date: Tue, 2 May 2023 11:51:06 +0200 Subject: [PATCH 3/3] chore: changeset --- .changeset/nice-jars-breathe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/nice-jars-breathe.md 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