@data-client/normalizr
Version:
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
14 lines (11 loc) • 562 B
text/typescript
import type { FetchFunction } from './types.js';
import type { Schema } from '../interface.js';
import type { Denormalize } from '../types.js';
/** What the function's promise resolves to */
export type ResolveType<E extends (...args: any) => any> =
ReturnType<E> extends Promise<infer R> ? R : never;
/** Fallback to schema if fetch function isn't defined */
export type InferReturn<F extends FetchFunction, S extends Schema | undefined> =
S extends undefined ? ReturnType<F>
: ReturnType<F> extends unknown ? Promise<Denormalize<S>>
: ReturnType<F>;