bananas-commerce
Version:
A client for bananas-commerce with support for TypeScript
20 lines (19 loc) • 1.15 kB
TypeScript
import type { ApiError, ApiResponse } from "../deps/deno.land/x/openapi_ts_fetch@2.1.0/index.js";
/**
* Formats a {@link VariableResult} for an {@link ApiResponse} using a {@link matcher}.
* If the data is not an object or an array, i.e. a primitive value, an object with the matched type
* is returned. The type is defined as the `_type` property.
*
* @remarks
* If `undefined` or `null` is returned from the {@link matcher}, `console.error` is used to print an error
* detailing that no response type could be resolved, and the response data is returned without a type.
*/
export declare function formatVariableResult<VR extends VariableResult<Record<string | number | symbol, any>>>(response: ApiResponse<VR[keyof VR]> | ApiError, matcher: (response: ApiResponse<any> | ApiError) => (VR extends VariableResult<infer R> ? keyof R : string | number | symbol) | undefined | void): VR;
/** @see {@link formatVariableResult} */
export type VariableResult<R extends Record<string | number | symbol, unknown>> = {
[K in keyof R]: R[K] extends object ? R[K] & {
readonly _type: K;
} : {
readonly _type: K;
};
}[keyof R];