We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Currenty, ApiResponse type is declared as:
type ApiResponse<T> = ApiErrorResponse<T> | ApiOkResponse<T>;
This means, both types for success and error is T
T
Allow end user to specify success/error types in following way:
// APISAUCE types type ApiErrorResponse<T> = { ok: false, data: T } type ApiOkResponse < T > = { ok: true, data: T } type ApiResponse<O, E = O> = ApiErrorResponse<E> | ApiOkResponse<O>; // Userland types type Ok = { firstName: string } type Err = { message: string } // Example of success/error responses // Success response const responseOk: ApiResponse<Ok, Err> = { ok: true, data: { firstName: 'Andrej' } } // Error response const responseErr: ApiResponse<Ok, Err> = { ok: false, data: { message: 'xx' } } // Example of `get` request const get = () => { return {} as ApiResponse<Ok, Err> } const response = get() if (response.ok === true) { console.log(response.data.firstName) } else { console.log(response.data.message) }
The text was updated successfully, but these errors were encountered:
Addressed with #219
Sorry, something went wrong.
No branches or pull requests
Currenty, ApiResponse type is declared as:
This means, both types for success and error is
T
Allow end user to specify success/error types in following way:
The text was updated successfully, but these errors were encountered: