mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
fix(types): Fix getImage type requesting for a second parameter (#6961)
This commit is contained in:
parent
6063f56573
commit
a695e44aed
3 changed files with 25 additions and 17 deletions
5
.changeset/nice-jars-breathe.md
Normal file
5
.changeset/nice-jars-breathe.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix getImage type
|
21
packages/astro/client-base.d.ts
vendored
21
packages/astro/client-base.d.ts
vendored
|
@ -3,7 +3,26 @@
|
||||||
declare module 'astro:assets' {
|
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
|
// Exporting things one by one is a bit cumbersome, not sure if there's a better way - erika, 2023-02-03
|
||||||
type AstroAssets = {
|
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;
|
getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService;
|
||||||
Image: typeof import('./components/Image.astro').default;
|
Image: typeof import('./components/Image.astro').default;
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,22 +29,6 @@ export async function getConfiguredImageService(): Promise<ImageService> {
|
||||||
return globalThis.astroAsset.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(
|
export async function getImage(
|
||||||
options: ImageTransform,
|
options: ImageTransform,
|
||||||
serviceConfig: Record<string, any>
|
serviceConfig: Record<string, any>
|
||||||
|
|
Loading…
Reference in a new issue