Skip to content
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

fix(types): account for undefined value for $fetch return type #2327

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

DamianGlowala
Copy link
Contributor

@DamianGlowala DamianGlowala commented Mar 29, 2024

πŸ”— Linked issue

nuxt/nuxt#26411

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ 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 is a continuation of #2286 which will fix not inferring undefined from server routes (checked this locally and works great).

The origin of the Exclude wrapper:
https://github.com/unjs/nitro/blame/adb6c5d1c7820feef63ed0851d7850f04d98ebb1/src/types/fetch.ts#L13

Confirmed with @danielroe whether there was any specific reason for excluding Error | void and he's not aware (hence it might be redundant but worth double checking).

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@pi0
Copy link
Member

pi0 commented Mar 29, 2024

Thanks for the PR dear @DamianGlowala but is there any hope that you please help on providing minimal Nitro reproduction or update the fixtures?

Even though i trust you already well tested this enough it doesn't feel right to merge changes untested like this.

@DamianGlowala
Copy link
Contributor Author

DamianGlowala commented Mar 29, 2024

Sure Pooya! Tried adding a fixture, but MiddlewareOf heavily depends on other types and ended up preparing a reproduction you can have a look at.

Launch locally the following reproduction, inspect type of $fetch within server/routes/test.ts, remove the Exclude wrapper underlined in red, go back to test.ts and hover over the response variable observing how undefined is correctly inferred.

image

@pi0 pi0 changed the title fix(types): update MiddlewareOf type to account for undefined fix(types): account for undefined value for $fetch return type Apr 2, 2024
@pi0 pi0 merged commit 91ef6d0 into unjs:main Apr 2, 2024
4 checks passed
@DamianGlowala DamianGlowala deleted the patch-1 branch April 2, 2024 22:42
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.

2 participants