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(nuxt): improve types for data fetching with transform #19487

Merged
merged 2 commits into from Mar 11, 2023

Conversation

clarkdo
Copy link
Member

@clarkdo clarkdo commented Mar 6, 2023

πŸ”— 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 pi0 and danielroe March 6, 2023 18:54
@codesandbox
Copy link

codesandbox bot commented Mar 6, 2023

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

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.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type wrong: default option of useFetch
2 participants