-
Notifications
You must be signed in to change notification settings - Fork 322
fix: infer configured providers and their modifiers in useImage
#2141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,17 +19,15 @@ export interface ResolvedImageModifiers extends ImageModifiers { | |
|
|
||
| type DefaultProvider = ProviderDefaults extends Record<'provider', unknown> ? ProviderDefaults['provider'] : never | ||
|
|
||
| export interface ImageOptions<Provider extends keyof ConfiguredImageProviders = DefaultProvider> { | ||
| provider?: Provider | ||
| type Sizes = Record<string, string | number> | string | ||
|
|
||
| export interface ImageOptions<TProvider extends keyof ConfiguredImageProviders = DefaultProvider> { | ||
| provider?: TProvider | ||
| preset?: string | ||
| densities?: string | ||
| modifiers?: Partial<Omit<ImageModifiers, 'format' | 'quality' | 'background' | 'fit'>> | ||
| & ('modifiers' extends keyof ConfiguredImageProviders[Provider] ? ConfiguredImageProviders[Provider]['modifiers'] : Record<string, unknown>) | ||
| sizes?: string | Record<string, any> | ||
| } | ||
|
|
||
| export interface ImageSizesOptions extends ImageOptions { | ||
| sizes: Record<string, string | number> | string | ||
| & ('modifiers' extends keyof ConfiguredImageProviders[TProvider] ? ConfiguredImageProviders[TProvider]['modifiers'] : Record<string, unknown>) | ||
| sizes?: Sizes | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this work in other contexts? e.g. if not passed to if it isn't respected then
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from what I can see, |
||
| } | ||
|
|
||
| export type ProviderGetImage<T = Record<string, unknown>> = (src: string, options: Omit<ImageOptions, 'modifiers'> & { modifiers: Partial<ResolvedImageModifiers> } & T, ctx: ImageCTX) => ResolvedImage | ||
|
|
@@ -84,11 +82,15 @@ export interface ImageSizes { | |
| } | ||
|
|
||
| export interface Img { | ||
| (source: string, modifiers?: ImageOptions['modifiers'], options?: ImageOptions): ResolvedImage['url'] | ||
| <TProvider extends keyof ConfiguredImageProviders = keyof ConfiguredImageProviders>( | ||
| source: string, | ||
| modifiers?: ImageOptions<TProvider>['modifiers'], | ||
| options?: ImageOptions<TProvider> | ||
| ): 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: <TProvider extends keyof ConfiguredImageProviders = keyof ConfiguredImageProviders>(source: string, options?: ImageOptions<TProvider>) => ResolvedImage | ||
| getSizes: <TProvider extends keyof ConfiguredImageProviders = keyof ConfiguredImageProviders>(source: string, options?: ImageOptions<TProvider>) => ImageSizes | ||
| getMeta: <TProvider extends keyof ConfiguredImageProviders = keyof ConfiguredImageProviders>(source: string, options?: ImageOptions<TProvider>) => Promise<ImageInfo> | ||
| } | ||
|
|
||
| export type $Img = Img & { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.