diff --git a/.nuxtrc b/.nuxtrc index 1e1fe8339..ae6553055 100644 --- a/.nuxtrc +++ b/.nuxtrc @@ -1 +1,2 @@ -setups.@nuxt/test-utils="4.0.0" \ No newline at end of file +setups.@nuxt/test-utils="4.0.0" +image.cloudinary.baseURL="https://res.cloudinary.com/nuxt/image/upload/" diff --git a/src/types/image.ts b/src/types/image.ts index ae0f06ffc..a1a8c2c4f 100644 --- a/src/types/image.ts +++ b/src/types/image.ts @@ -84,11 +84,11 @@ export interface ImageSizes { } export interface Img { - (source: string, modifiers?: ImageOptions['modifiers'], options?: ImageOptions): ResolvedImage['url'] + (source: string, modifiers?: ImageOptions['modifiers'], options?: ImageOptions): ResolvedImage['url'] options: CreateImageOptions - getImage: (source: string, options?: ImageOptions) => ResolvedImage - getSizes: (source: string, options?: ImageOptions, sizes?: string[]) => ImageSizes - getMeta: (source: string, options?: ImageOptions) => Promise + getImage: (source: string, options?: ImageOptions) => ResolvedImage + getSizes: (source: string, options?: ImageOptions, sizes?: string[]) => ImageSizes + getMeta: (source: string, options?: ImageOptions) => Promise } export type $Img = Img & { diff --git a/test/nuxt/use-image.test.ts b/test/nuxt/use-image.test.ts index e0547ef1f..650960d15 100644 --- a/test/nuxt/use-image.test.ts +++ b/test/nuxt/use-image.test.ts @@ -43,4 +43,19 @@ describe('image helper', () => { }, }) }) + + it('accepts non-default configured providers', () => { + const img = useImage() + + // All Img interface methods should accept a configured non-default provider + img.getImage('/test.png', { provider: 'cloudinary' }) + img.getSizes('/test.png', { provider: 'cloudinary' }) + img('/test.png', {}, { provider: 'cloudinary', modifiers: { roundCorner: 'true' } }) + + // @ts-expect-error ipx does not accept roundCorner as a modifier + img('/test.png', {}, { provider: 'ipx', modifiers: { roundCorner: 'true' } }) + + // @ts-expect-error this provider is not configured, so it should throw an error + img('/test.png', {}, { provider: 'unknown-provider' }) + }) })