Skip to content
module@warp-drive/core/request

Function withReactiveResponse() ​

ts
function withReactiveResponse<T, M extends ObjectValue | undefined = ObjectValue | undefined, E extends object = object, EM extends ObjectValue | undefined = M>(obj: RequestInfo): RequestInfo<ReactiveDataDocument<T, M, E, EM>> & {
  ___(unique) Symbol(RequestSignature): ReactiveDataDocument<T, M, E, EM>;
};

Defined in: warp-drive-packages/core/src/request.ts:103

Brands the supplied object with the supplied response type wrapped in ReactiveDataDocument. This is a convenience for the common case of using withResponseType with ReactiveDataDocument.

Like withResponseType, call it inside a builder rather than where the request is made. The Typing Requests guide shows how to use it.

ts
import { withReactiveResponse } from '@warp-drive/core/request';
import type { User } from '#/data/user.ts'

export function getUser(id: string) {
  return withReactiveResponse<User>({ url: `/users/${id}` });
}

const result = await store.request(getUser('1'));

result.content.data; // will have type User

Pass a second type param to declare the meta the endpoint returns:

ts
type PageMeta = { page: { limit: number; offset: number }; total?: number };

export function getUsers() {
  return withReactiveResponse<User[], PageMeta>({ url: '/users' });
}

const result = await store.request(getUsers());

result.content.meta?.total; // number | undefined

Type Parameters ​

T ​

T

M ​

M extends ObjectValue | undefined = ObjectValue | undefined

E ​

E extends object = object

EM ​

EM extends ObjectValue | undefined = M

Parameters ​

obj ​

RequestInfo

Returns ​

Released under the MIT License.