Skip to content

fix(nuxt): improve types for data fetching with transform#19487

Merged
danielroe merged 2 commits into
mainfrom
fix/async-data-option
Mar 11, 2023
Merged

fix(nuxt): improve types for data fetching with transform#19487
danielroe merged 2 commits into
mainfrom
fix/async-data-option

Conversation

@clarkdo

@clarkdo clarkdo commented Mar 6, 2023

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #14437

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

Current AsyncDataOptions is not able to infer correct type on default option when transform exists, this pr fixes the issue and also improve type inference on composables useAsyncData/useLazyAsyncData/useFetch/useLazyFetch by inferring transformed data instead of transform function.

👉 Migration

⚠️ This is a potential breaking change if the user is using generics explicitly. ⚠️

No migration is needed if you are only using the first generic of useFetch or useAsyncData. But if you were typing more fields, or trying to clone the Nuxt types, you will need to update your types to use (instead of a type for the transform function, you will provide a type for the return value of the transform function).

This will probably not affect you as the types were buggy in this case (which was what this PR was solving).

📝 Checklist

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

@clarkdo clarkdo requested review from danielroe and pi0 March 6, 2023 18:54
@codesandbox

codesandbox Bot commented Mar 6, 2023

Copy link
Copy Markdown

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@danielroe danielroe added 3.x types 🐛 bug Something isn't working as expected labels Mar 6, 2023

@danielroe danielroe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks really nice, thank you! ❤️

Do you think there is a way we can keep this from being a breaking change, e.g. by using a function signature overload?

@danielroe danielroe mentioned this pull request Mar 8, 2023
@danielroe danielroe changed the title fix(type): improve type inference on asyncData option fix(nuxt): improve type inference on asyncData option Mar 11, 2023
@danielroe danielroe changed the title fix(nuxt): improve type inference on asyncData option fix(nuxt): improve types for data fetching with transform Mar 11, 2023
@danielroe danielroe merged commit 4de4de1 into main Mar 11, 2023
@danielroe danielroe deleted the fix/async-data-option branch March 11, 2023 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x 🐛 bug Something isn't working as expected types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type wrong: default option of useFetch

2 participants