module@warp-drive/core/request
Function withResponseType()
ts
function withResponseType<T>(obj: RequestInfo): RequestInfo<T> & {
"___(unique) Symbol(RequestSignature)": T;
};Defined in: warp-drive-packages/core/src/request.ts:53
Brands the supplied object with the supplied response type.
Call it inside a builder, so the type is part of the builder's contract and every caller gets it through inference. Calling it inline where the request is made is a cast. The Typing Requests guide shows how to use it.
ts
import type { ReactiveDataDocument } from '@warp-drive/core/reactive';
import { withResponseType } from '@warp-drive/core/request';
import type { User } from '#/data/user.ts'
export function getUser(id: string) {
return withResponseType<ReactiveDataDocument<User>>({ url: `/users/${id}` });
}
const result = await store.request(getUser('1'));
result.content.data; // will have type UserType Parameters
T
T
Parameters
obj
Returns
RequestInfo<T> & { "___(unique) Symbol(RequestSignature)": T; }