diff --git a/packages/astro/components/Picture.astro b/packages/astro/components/Picture.astro index bc53cd8cc..c8613581c 100644 --- a/packages/astro/components/Picture.astro +++ b/packages/astro/components/Picture.astro @@ -1,9 +1,9 @@ --- -import { LocalImageProps, RemoteImageProps, getImage } from 'astro:assets'; -import { GetImageResult, ImageOutputFormat } from '../dist/@types/astro'; +import { getImage, type LocalImageProps, type RemoteImageProps } from 'astro:assets'; +import type { GetImageResult, ImageOutputFormat } from '../dist/@types/astro'; import { isESMImportedImage } from '../dist/assets/internal'; import { AstroError, AstroErrorData } from '../dist/core/errors/index.js'; -import { HTMLAttributes } from '../types'; +import type { HTMLAttributes } from '../types'; type Props = (LocalImageProps | RemoteImageProps) & { formats?: ImageOutputFormat[]; @@ -11,7 +11,7 @@ type Props = (LocalImageProps | RemoteImageProps) & { pictureAttributes?: HTMLAttributes<'picture'>; }; -const {formats = ["webp"], pictureAttributes = {}, ...props} = Astro.props; +const { formats = ['webp'], pictureAttributes = {}, ...props } = Astro.props; if (props.alt === undefined || props.alt === null) { throw new AstroError(AstroErrorData.ImageMissingAlt); @@ -47,7 +47,10 @@ if (fallbackImage.srcSet.values.length > 0) { { Object.entries(optimizedImages).map(([_, image]) => ( - + )) } diff --git a/packages/astro/src/assets/types.ts b/packages/astro/src/assets/types.ts index f8ee91cd8..8fada3e41 100644 --- a/packages/astro/src/assets/types.ts +++ b/packages/astro/src/assets/types.ts @@ -97,19 +97,26 @@ type ImageSharedProps = T & { * ``` */ height?: number | `${number}`; - /** - * A list of widths to generate images for. The value of this property will be used to assign the `srcset` property on the final `img` element. - * - * This attribute is incompatible with `densities`. - */ - widths?: number[]; - /** - * A list of densities to generate images for. The value of this property will be used to assign the `srcset` property on the final `img` element. - * - * This attribute is incompatible with `widths`. - */ - densities?: (number | `${number}x`)[]; -}; +} & ( + | { + /** + * A list of widths to generate images for. The value of this property will be used to assign the `srcset` property on the final `img` element. + * + * This attribute is incompatible with `densities`. + */ + widths?: number[]; + densities?: never; + } + | { + /** + * A list of densities to generate images for. The value of this property will be used to assign the `srcset` property on the final `img` element. + * + * This attribute is incompatible with `widths`. + */ + densities?: (number | `${number}x`)[]; + widths?: never; + } + ); export type LocalImageProps = ImageSharedProps & { /**