Skip to content

feat: improve isNuxtError() type inference#28814

Merged
danielroe merged 1 commit intonuxt:mainfrom
gianlucadifrancesco:fix/isnuxterror-type
Sep 3, 2024
Merged

feat: improve isNuxtError() type inference#28814
danielroe merged 1 commit intonuxt:mainfrom
gianlucadifrancesco:fix/isnuxterror-type

Conversation

@gianlucadifrancesco
Copy link
Copy Markdown
Contributor

🔗 Linked issue

resolves #28813

📚 Description

This PR will improve the type inference of isNuxtError(), without changing its implementation at all.

The change is a one-liner, very simple, but it offers several advantages:

  • Wider param type: the runtime code is already resilient to all parameter types, so its type is set to unknown to improve DX and avoid casting.
  • Always infer type: in this way, the type inference (error is NuxtError<DataT>) will always be applied after being asserted.
  • Mandatory param: I thought it was good to avoid using isNuxtError() without a param, as it's not particularly meaningful on its own.

@bolt-new-by-stackblitz
Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@gianlucadifrancesco gianlucadifrancesco changed the title feat: improve isNuxtError type inference feat: improve isNuxtError() type inference Sep 3, 2024
@danielroe danielroe merged commit 0c9aa08 into nuxt:main Sep 3, 2024
@danielroe
Copy link
Copy Markdown
Member

Thank you!

@github-actions github-actions bot mentioned this pull request Sep 3, 2024
@gianlucadifrancesco gianlucadifrancesco deleted the fix/isnuxterror-type branch September 3, 2024 21:51
@github-actions github-actions bot mentioned this pull request Sep 4, 2024
Kamsou pushed a commit to Kamsou/nuxt that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve isNuxtError() type inference

2 participants