sanity-io/image-url

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>;

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()!;
  }

  // ...
}

๐Ÿ‘