summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Erika <3019731+Princesseuh@users.noreply.github.com> 2023-05-02 14:23:37 +0200
committerGravatar GitHub <noreply@github.com> 2023-05-02 14:23:37 +0200
commita695e44aed6e2f5d32cb950d4237be6e5657ba98 (patch)
treeba3e80a99989da076fcef69d0737f4ffd84f0110
parent6063f5657392a74b6ffc4d5e0de5463c217a8563 (diff)
downloadastro-a695e44aed6e2f5d32cb950d4237be6e5657ba98.tar.gz
astro-a695e44aed6e2f5d32cb950d4237be6e5657ba98.tar.zst
astro-a695e44aed6e2f5d32cb950d4237be6e5657ba98.zip
fix(types): Fix getImage type requesting for a second parameter (#6961)
Diffstat (limited to '')
-rw-r--r--.changeset/nice-jars-breathe.md5
-rw-r--r--packages/astro/client-base.d.ts21
-rw-r--r--packages/astro/src/assets/internal.ts16
3 files changed, 25 insertions, 17 deletions
diff --git a/.changeset/nice-jars-breathe.md b/.changeset/nice-jars-breathe.md
new file mode 100644
index 000000000..1a47e9bc3
--- /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 52bd5870f..15c1fb905 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 });
+ * ---
+ * <img src={optimizedImage.src} {...optimizedImage.attributes} />
+ * ```
+ *
+ * This is functionally equivalent to using the `<Image />` component, as the component calls this function internally.
+ */
+ getImage: (
+ options: import('./dist/assets/types.js').ImageTransform
+ ) => Promise<import('./dist/assets/types.js').GetImageResult>;
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 945b5a3e8..c4b8ca751 100644
--- a/packages/astro/src/assets/internal.ts
+++ b/packages/astro/src/assets/internal.ts
@@ -29,22 +29,6 @@ export async function getConfiguredImageService(): Promise<ImageService> {
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 });
- * ---
- * <img src={optimizedImage.src} {...optimizedImage.attributes} />
- * ```
- *
- * This is functionally equivalent to using the `<Image />` component, as the component calls this function internally.
- */
export async function getImage(
options: ImageTransform,
serviceConfig: Record<string, any>