Skip to content

Conversation

@kaki0704
Copy link

@kaki0704 kaki0704 commented Dec 6, 2025

resolves #2014

πŸ”— Linked issue

resolves #2014

❓ 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

The ProviderDefaults interface was missing from src/index.d.ts, causing DefaultProvider type to resolve to never during development.

This happened because in src/types/image.ts, the DefaultProvider type is defined as:

type DefaultProvider = ProviderDefaults extends Record<'provider', unknown> ? ProviderDefaults['provider'] : never

Without ProviderDefaults.provider being defined, the conditional type resolves to never, breaking provider type inference.

Changes:

  • Added ProviderDefaults interface with provider: 'ipx' to src/index.d.ts
  • Removed unused @ts-expect-error directives from tests (now that types work correctly)

Testing:

  • pnpm test:types passes
  • Unit tests pass

@kaki0704 kaki0704 requested a review from danielroe as a code owner December 6, 2025 20:50
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 6, 2025

Open in StackBlitz

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

commit: 53ed7ec

@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2025

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 6.99%. Comparing base (9fc971d) to head (53ed7ec).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2056   +/-   ##
=====================================
  Coverage   6.99%   6.99%           
=====================================
  Files         78      78           
  Lines       3629    3629           
  Branches     140     140           
=====================================
  Hits         254     254           
  Misses      3326    3326           
  Partials      49      49           

β˜” 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.

Comment on lines 32 to 33
// @ts-expect-error this is not a valid modifier for ipx
alkj: false,
Copy link
Member

@danielroe danielroe Dec 8, 2025

Choose a reason for hiding this comment

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

this is a correct test to make sure that modifiers are typed correctly (in other words, you can't pass a nonsense modifier to them)

we wouldn't want to get rid of this test

Copy link
Author

Choose a reason for hiding this comment

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

I've reverted the @ts-expect-error removal. I now understand this is a valid test to ensure invalid modifiers are caught by the type system.

src/index.d.ts Outdated
Comment on lines 4 to 6
interface ProviderDefaults {
provider: 'ipx'
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't believe this is a correct fix - this file is only used when developing nuxt/image and is not included in the dist files... it won't make any difference to the experience of an end user

Copy link
Author

Choose a reason for hiding this comment

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

You're correct that this file isn't included in the dist, so it wouldn't help end users.

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.

I don't think this PR would have any effect on the built code of the module.

if you think it does, would you build and diff it with https://app.unpkg.com/@nuxt/image@2.0.0/files/dist/module.d.ts?

πŸ™

@kaki0704
Copy link
Author

kaki0704 commented Dec 8, 2025

Thank you for taking the time to review and for the helpful feedback! πŸ™
I've updated the PR to only modify src/types/image.ts.

@kaki0704 kaki0704 requested a review from danielroe December 8, 2025 13:03
}

type DefaultProvider = ProviderDefaults extends Record<'provider', unknown> ? ProviderDefaults['provider'] : never
type DefaultProvider = ProviderDefaults extends Record<'provider', infer P> ? P : keyof ConfiguredImageProviders
Copy link
Member

Choose a reason for hiding this comment

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

I still don't think this is the right fix - we need to know the specific default provider (likely ipx) in case provider is not passed into any image functions.

@kaki0704
Copy link
Author

kaki0704 commented Dec 8, 2025

I've taken another look. Not entirely sure I got it right, but I added provider: 'ipx' to ProviderDefaults in src/types/module.ts.

Could you please check if this is the correct approach?πŸ™‡πŸ»β€β™‚οΈ

@kaki0704 kaki0704 requested a review from danielroe December 8, 2025 22:20
@danielroe
Copy link
Member

I don't think this is right either. that interface is populated dynamically via types that nuxt generates, which should certainly include ipx

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.

Provider types are not passed correctly

3 participants