Skip to content

fix(types): accept all configured providers in Img interface#2175

Open
ispitsyn wants to merge 1 commit intonuxt:mainfrom
ispitsyn:fix/img-provider-type
Open

fix(types): accept all configured providers in Img interface#2175
ispitsyn wants to merge 1 commit intonuxt:mainfrom
ispitsyn:fix/img-provider-type

Conversation

@ispitsyn
Copy link

Summary

  • The Img interface call signature uses ImageOptions without a generic parameter, defaulting to DefaultProvider ("ipx")
  • This causes TS2322 when passing any non-default configured provider (e.g. "directus") to useImage() options
  • Widen provider type in Img to keyof ConfiguredImageProviders so all configured providers are accepted

Reproduction

// nuxt.config.ts — directus provider is configured
image: {
  providers: {
    directus: { provider: 'directus', options: { baseURL: '...' } }
  }
}

// composable
const img = useImage();
img('id', {}, { provider: 'directus' });
//                         ^^^^^^^^^^
// TS2322: Type '"directus"' is not assignable to type '"ipx"'

Fix

Changed ImageOptionsImageOptions<keyof ConfiguredImageProviders> in the Img interface (call signature, getImage, getSizes, getMeta).

Fixes #2174

🤖 Generated with Claude Code

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>
@ispitsyn ispitsyn requested a review from danielroe as a code owner March 17, 2026 10:03
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 17, 2026

Open in StackBlitz

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

commit: 824b9ba

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2786205a-d00a-41a0-ab2e-ca23356e4672

📥 Commits

Reviewing files that changed from the base of the PR and between 5be826f and 824b9ba.

📒 Files selected for processing (1)
  • src/types/image.ts

📝 Walkthrough

Walkthrough

This change fixes a TypeScript type issue in the image module where Img-related methods only accepted the default image provider in their options parameter. The fix widens the type parameter from a default-provider-only restriction to accept all configured image providers. The callable Img interface, getImage, getSizes, and getMeta methods are updated to use ImageOptions<keyof ConfiguredImageProviders> instead of the generic ImageOptions, enabling usage of all configured providers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing types to accept all configured providers in the Img interface.
Description check ✅ Passed The description clearly explains the problem, reproduction case, and fix related to the ImageOptions type narrowing.
Linked Issues check ✅ Passed The PR successfully addresses issue #2174 by narrowing ImageOptions to use keyof ConfiguredImageProviders in all Img interface methods, enabling all configured providers to be accepted.
Out of Scope Changes check ✅ Passed All changes in src/types/image.ts are directly scoped to fixing the ImageOptions type parameter in the Img interface methods, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.52%. Comparing base (5be826f) to head (824b9ba).

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.
📢 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.

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.

Img call signature does not accept configured providers other than default

2 participants