fix(types): accept all configured providers in Img interface#2175
fix(types): accept all configured providers in Img interface#2175
Conversation
The Img interface call signature used ImageOptions without a generic
parameter, defaulting to DefaultProvider ("ipx"). This caused
TS2322 errors when passing any non-default provider (e.g. "directus")
to useImage() options, even when the provider is properly configured
in nuxt.config.ts.
Widen the provider type to keyof ConfiguredImageProviders so all
configured providers are accepted.
Fixes nuxt#2174
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
commit: |
📝 WalkthroughWalkthroughUpdated TypeScript typings for the image module so Img-related callables and methods use ImageOptions instead of a non-generic ImageOptions. The change ensures the Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2175 +/- ##
=======================================
Coverage 32.52% 32.52%
=======================================
Files 7 7
Lines 372 372
Branches 131 131
=======================================
Hits 121 121
Misses 194 194
Partials 57 57 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/nuxt/use-image.test.ts (1)
58-59: Clarify test intent: runtime vs type-level error.The comment says "should throw an error" but
@ts-expect-erroronly suppresses the compile-time TypeScript error. The test doesn't actually assert that a runtime error is thrown (unlike the "Deny undefined provider" test on lines 16-21 which usesexpect(...).toThrow(Error)).If runtime validation is also expected, consider wrapping in an assertion:
💡 Suggested improvement
- // `@ts-expect-error` this provider is not configured, so it should throw an error - img('/test.png', {}, { provider: 'unknown-provider' }) + // `@ts-expect-error` this provider is not configured + expect(() => img('/test.png', {}, { provider: 'unknown-provider' })).toThrow(Error)Alternatively, update the comment to clarify it's only testing the type-level rejection.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/nuxt/use-image.test.ts` around lines 58 - 59, The test currently uses `@ts-expect-error` but does not assert a runtime error for the call to img('/test.png', {}, { provider: 'unknown-provider' }), so either make the intent explicit: if you expect runtime validation to throw, wrap the call in an assertion like expect(() => img('/test.png', {}, { provider: 'unknown-provider' })).toThrow(Error) (mirror the "Deny undefined provider" test), or if you only intend to test type-level rejection, update the inline comment to state "only testing type-level rejection; no runtime assertion" so the test intent is clear; locate the call to img in use-image.test.ts and change the assertion or comment accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@test/nuxt/use-image.test.ts`:
- Around line 58-59: The test currently uses `@ts-expect-error` but does not
assert a runtime error for the call to img('/test.png', {}, { provider:
'unknown-provider' }), so either make the intent explicit: if you expect runtime
validation to throw, wrap the call in an assertion like expect(() =>
img('/test.png', {}, { provider: 'unknown-provider' })).toThrow(Error) (mirror
the "Deny undefined provider" test), or if you only intend to test type-level
rejection, update the inline comment to state "only testing type-level
rejection; no runtime assertion" so the test intent is clear; locate the call to
img in use-image.test.ts and change the assertion or comment accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9fb432b8-fbfc-4434-af81-309b5206a707
📒 Files selected for processing (2)
.nuxtrctest/nuxt/use-image.test.ts
✅ Files skipped from review due to trivial changes (1)
- .nuxtrc
Summary
Imginterface call signature usesImageOptionswithout a generic parameter, defaulting toDefaultProvider("ipx")TS2322when passing any non-default configured provider (e.g."directus") touseImage()optionsprovidertype inImgtokeyof ConfiguredImageProvidersso all configured providers are acceptedReproduction
Fix
Changed
ImageOptions→ImageOptions<keyof ConfiguredImageProviders>in theImginterface (call signature,getImage,getSizes,getMeta).Fixes #2174
🤖 Generated with Claude Code