Type Extraction

Type extraction

vovk module provides a collection of useful types that described in more details at API documentation. It's worthy to mention the most oftenly used types here:

import { UserController, StreamController } from 'vovk-client';
import type { VovkBody, VovkQuery, VovkParams, VovkReturnType, VovkYieldType } from 'vovk';
// infer body
type Body = VovkBody<typeof UserController.updateUser>;
// infer query
type Query = VovkQuery<typeof UserController.updateUser>;
// infer params
type Params = VovkParams<typeof UserController.updateUser>;
// infer return type
type Return = VovkReturnType<typeof UserController.updateUser>;
// infer yield type from stream methods
type Yield = VovkYieldType<typeof StreamController.streamTokens>;

For example, if you want to create a custom function that makes requests to the server, you can borrow types from the client to build the arguments.

import { UserController } from 'vovk-client';
import type { VovkBody, VovkQuery } from 'vovk';
export function updateUser(
    id: VovkQuery<typeof UserController.updateUser>['id'],
    body: VovkBody<typeof UserController.updateUser>,
) {
    return UserController.updateUser({
        query: { id },

The exported updateUser can be called the following way:

import { updateUser } from './wherever-you-put-it';
// ...
await updateUser('69', { firstName: 'John', lastName: 'Doe' });