Skip to content

Conversation

@nathanchase
Copy link
Contributor

@nathanchase nathanchase commented May 16, 2025

πŸ”— Linked issue

resolves #1843

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This modifies the ImageModifiers interface to support custom provider modifiers by adding an index signature.

@nathanchase nathanchase requested a review from danielroe as a code owner May 16, 2025 01:05
@pkg-pr-new
Copy link

pkg-pr-new bot commented May 16, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@nuxt/image@1844

commit: ca0a20f

@danielroe
Copy link
Member

danielroe commented May 16, 2025

I think instead of this (which removes type safety for modifiers) we should amend useImage to respect the generic provider type.

@nathanchase
Copy link
Contributor Author

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!

Copilot AI review requested due to automatic review settings October 29, 2025 10:05
Copy link

Copilot AI left a 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 ImageOptions interface with generic provider type parameter for better type safety
  • Modified modifiers type 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 presets field uses a non-generic ImageOptions type, which loses the provider-specific type safety introduced by the generic parameter. This could allow presets to be defined with invalid provider options. Consider using ImageOptions<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.

Comment on lines +24 to +25
modifiers?: Partial<Omit<ImageModifiers, 'format' | 'quality' | 'background' | 'fit'>>
& ('modifiers' extends keyof ConfiguredImageProviders[Provider] ? ConfiguredImageProviders[Provider]['modifiers'] : Record<string, unknown>)
Copy link

Copilot AI Oct 29, 2025

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.

Copilot uses AI. Check for mistakes.
@danielroe danielroe changed the title feat: Add support for custom provider modifiers in ImageModifiers int… feat: strongly type $Img/useImage methods Nov 3, 2025
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
βœ… Project coverage is 7.02%. Comparing base (7c0555d) to head (ca0a20f).

Files with missing lines Patch % Lines
src/module.ts 0.00% 2 Missing ⚠️
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.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you ❀️

@danielroe danielroe merged commit 3e1f1f6 into nuxt:main Nov 3, 2025
7 checks passed
This was referenced Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support custom provider modifiers in interface

3 participants