-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
Clear and concise description of the problem
I believe that when dealing with calls with a more complex body, it can be easy to make a mistake, so I think there could be a possibility to pass a pre-existing generic type when calling method functions.
In addition, there are Content-Type aliases that are specific to useFetch but are not typed (json and text).
Suggested solution
Allowing a generic type in functions similar to what already occurs in the json method, and the creation of a type for accepted types:
type PayloadType = 'json' | 'text' | (string & {})
export interface UseFetchReturn<T> {
// methods
get: () => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
post: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
put: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
delete: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
patch: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
head: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
options: <P = unknown>(payload?: MaybeRefOrGetter<P>, type?: PayloadType) => UseFetchReturn<T> & PromiseLike<UseFetchReturn<T>>
}This allows you to indicate the type of payload, if necessary, and there is an auto-fill for the type (while maintaining the possibility of any string).
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation