lorenzodejong / next-sanity-image

Utility for using responsive images hosted on the Sanity.io CDN with the Next.js image component.
MIT License
149 stars 20 forks source link

Typescript is complaining when the image argument is "string | null" #13

Closed PSalaun closed 3 years ago

PSalaun commented 3 years ago

Hello,

I'm creating a component that may or may not receive an image from Sanity, so the image type is "string | null". However TS is not happy with it (using version 3.1.4), as I get Argument of type 'string | null' is not assignable to parameter of type 'null'. Type 'string' is not assignable to type 'null'. when passing the image to useNextSanityImage. It does the same if I replace string by SanityImageSource.

As the hook can handle null images, it should be ok to pass this argument, shouldn't it?

lorenzodejong commented 3 years ago

Thanks for reporting this bug! This was a recently introduced feature and it looks like this only occurs when explicitly typing the image param. I've just released 3.1.5 with a fix, please let me know if this solves your issue!