Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .nuxtrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
setups.@nuxt/test-utils="4.0.0"
setups.@nuxt/test-utils="4.0.0"
image.cloudinary.baseURL="https://res.cloudinary.com/nuxt/image/upload/"
8 changes: 4 additions & 4 deletions src/types/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<keyof ConfiguredImageProviders>): ResolvedImage['url']
options: CreateImageOptions
getImage: (source: string, options?: ImageOptions) => ResolvedImage
getSizes: (source: string, options?: ImageOptions, sizes?: string[]) => ImageSizes
getMeta: (source: string, options?: ImageOptions) => Promise<ImageInfo>
getImage: (source: string, options?: ImageOptions<keyof ConfiguredImageProviders>) => ResolvedImage
getSizes: (source: string, options?: ImageOptions<keyof ConfiguredImageProviders>, sizes?: string[]) => ImageSizes
getMeta: (source: string, options?: ImageOptions<keyof ConfiguredImageProviders>) => Promise<ImageInfo>
}

export type $Img = Img & {
Expand Down
15 changes: 15 additions & 0 deletions test/nuxt/use-image.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,19 @@
},
})
})

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' })

Check failure on line 51 in test/nuxt/use-image.test.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Type '"cloudinary"' is not assignable to type '"ipx"'.
img.getSizes('/test.png', { provider: 'cloudinary' })

Check failure on line 52 in test/nuxt/use-image.test.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Type '"cloudinary"' is not assignable to type '"ipx"'.
img('/test.png', {}, { provider: 'cloudinary', modifiers: { roundCorner: 'true' } })

Check failure on line 53 in test/nuxt/use-image.test.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Object literal may only specify known properties, and 'roundCorner' does not exist in type 'Partial<Omit<ImageModifiers, "format" | "quality" | "background" | "fit">> & Partial<IPXModifiers>'.

Check failure on line 53 in test/nuxt/use-image.test.ts

View workflow job for this annotation

GitHub Actions / ci (ubuntu-latest)

Type '"cloudinary"' is not assignable to type '"ipx"'.

// @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' })
})
})
Loading