-
Notifications
You must be signed in to change notification settings - Fork 313
feat: strongly type $Img/useImage methods
#1844
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
feat: strongly type $Img/useImage methods
#1844
Conversation
commit: |
|
I think instead of this (which removes type safety for modifiers) we should amend |
β¦interfaces and functions
|
Ok, I've updated the PR to preserve type-safety based on the selected provider. Please review and let me know what you think! Thanks, @danielroe! |
β¦ustom-provider-modifiers
β¦ustom-provider-modifiers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds TypeScript type safety improvements for image provider options and modifiers. It introduces generic typing to the ImageOptions interface that validates provider names and their specific modifiers at compile time.
- Enhanced
ImageOptionsinterface with generic provider type parameter for better type safety - Modified
modifierstype definition to support provider-specific modifiers - Added comprehensive type-checking tests to verify correct TypeScript behavior
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/types/image.ts | Added generic type parameter to ImageOptions for provider validation and modifier type checking; updated ProviderGetImage to handle typed options |
| test/nuxt/use-image.test.ts | Added test cases with @ts-expect-error directives to verify TypeScript catches invalid providers and modifiers; reformatted existing test for consistency |
Comments suppressed due to low confidence (1)
src/types/image.ts:55
- The
presetsfield uses a non-genericImageOptionstype, which loses the provider-specific type safety introduced by the generic parameter. This could allow presets to be defined with invalid provider options. Consider usingImageOptions<any>or a more specific type to maintain type safety.
presets: { [name: string]: ImageOptions }
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| modifiers?: Partial<Omit<ImageModifiers, 'format' | 'quality' | 'background' | 'fit'>> | ||
| & ('modifiers' extends keyof ConfiguredImageProviders[Provider] ? ConfiguredImageProviders[Provider]['modifiers'] : Record<string, unknown>) |
Copilot
AI
Oct 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The modifiers type definition is complex and spans multiple lines in a way that reduces readability. Consider extracting this into a separate type alias (e.g., type ImageModifiersForProvider<Provider>) to improve code maintainability and make the intent clearer.
$Img/useImage methods
Codecov Reportβ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1844 +/- ##
========================================
- Coverage 7.02% 7.02% -0.01%
========================================
Files 77 77
Lines 3573 3575 +2
Branches 138 138
========================================
Hits 251 251
- Misses 3274 3276 +2
Partials 48 48 β View full report in Codecov by Sentry. π New features to boost your workflow:
|
danielroe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you β€οΈ
π Linked issue
resolves #1843
β Type of change
π Description
This modifies the ImageModifiers interface to support custom provider modifiers by adding an index signature.