feat: add useStrapi
composable with correct types
#279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types of changes
Description
This PR aims to fix broken types without introducing breaking changes.
See:
To summarise the type issues:
To fix the types without breaking anything, I've introduced a new composable
useStrapi
which is a simple wrapper to the existing v3 or v4 client, depending on which version is being used, with the correct types.The types for the client allow a user to either set a default type for all requests from the composable
useStrapi<MyData>
and / or override the single data return types from the functionsfind<Book>('book')
useStrapi3
anduseStrapi4
are deprecated in favour of this to notify users they should swap over, this can be removed but I think it's worth while to have a single composable in the docs which have correct typesI believe these changes are a huge DX improvement:
While this shouldn't break anything, it should be a minor bump and simple migration docs should be included in the release
While these changes have minimal scope for breaking things there are no test cases and I've never used strapi, so ideally someone would test this PR locally before merging.
Migration
Check the docs for latest type guidelines.
Previous version
New version
or
Checklist: