Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/content/docs/en/reference/image-service-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,33 @@ export default defineConfig({
});
```

## Typing custom image service props

<p><Since v="5.16.6" /></p>

If your image service supports additional props in Astro’s `<Image>` component, `<Picture>` component, or the `getImage()` function, you can add types for these by extending the `Astro.CustomImageProps` interface.

For example, to add a custom `blur` prop that your image service supports:

```ts
declare namespace Astro {
interface CustomImageProps {
/** Apply a Gaussian blur with this radius to the image. */
blur?: number;
}
}
```

You can expose these types to users by making your image service an [Astro integration](/en/reference/integrations-reference/) and using the [`injectTypes()`](/en/reference/integrations-reference/#injecttypes-option) helper.

Then, users will be able to get autocomplete and type safety for your custom props:

```astro
<Image blur="yes" src={myPhoto} />
// ^^^^^^^^^^
// Type 'string' is not assignable to type 'number | undefined'.
```

## Utilities

Astro exposes a number of helper functions that can be used to develop a custom image service. These utilities can be imported from `astro/assets/utils`:
Expand Down