Export the ImageUrlBuilder type
Closed this issue ยท 4 comments
Svish commented
Wanted to accept an ImageUrlBuilder
as a prop in a component, but the type isn't exported, as far as I can see. ๐
Like, I can "see" it via my IDE, but since it's not exported, I can't actually use it as a prop or function parameter type. ๐
Please export the ImageUrlBuilder
type?
Svish commented
Worked around it as follows, but really shouldn't be necessary working around this. Should just be an exported type from the library.
import imageUrlBuilder from '@sanity/image-url';
type ImageUrlBuilder = ReturnType<typeof imageUrlBuilder>;
rexxars commented
Could you see if 0.140.16 fixes the issue?
Svish commented
@rexxars Looking at the diff for that version I assume it will, but checking now (if only my slow connection could hurry up) to be sure. Will close the issue when verified. ๐
Svish commented
Yep, I can use the type in my code now:
import React from 'react';
import { ImageUrlBuilder } from '@sanity/image-url/lib/types/builder';
interface ImageProps extends Omit<React.HTMLProps<HTMLImageElement>, 'src'> {
src: string | ImageUrlBuilder;
}
export default function Image(props: ImageProps) {
if (typeof props.src !== 'string') {
props.src = props.src.url()!;
}
// ...
}
๐