Skip to content

Type Generation

Vitek automatically generates types and client helpers for your API.

api.types.ts (TypeScript projects only)

Generated file contains route types and parameter definitions:

typescript
// Auto-generated by Vitek - DO NOT EDIT

export type VitekParams = Record<string, string>;
export type VitekQuery = Record<string, string | string[]>;

export interface UsersIdGetParams extends VitekParams {
  id: string;
}

export type PostsPostBody = {
  title: string;
  content: string;
  authorId: number;
  tags?: string[];
};

export type PostsIndexGetQuery = {
  limit?: number;
  offset?: number;
};

export type VitekRoute =
  | { pattern: "users/:id"; method: "get"; params: UsersIdGetParams }
  | { pattern: "posts"; method: "post"; params: PostsPostBody };
// ...

api.services.ts (TypeScript) or api.services.js (JavaScript)

Generated helper functions to call the API from the frontend:

typescript
import { getUsersById, postPosts, getPostsIdComments } from "./api.services";

// GET /api/users/:id
const user = await getUsersById({ id: "123" });

// POST /api/posts (with body)
const post = await postPosts({
  title: "Hello",
  content: "World",
});

// GET /api/posts/:id/comments (with params + query)
const comments = await getPostsIdComments(
  { id: "123" },       // params
  { limit: 10, offset: 0 }  // query
);

Generated services behavior:

  • Only necessary parameters are included (params, body, query only when defined in the route)
  • Unique function names are generated from path and method
  • Full types for autocomplete in TypeScript projects
  • Last parameter is always options?: RequestInit for fetch customization

Note: JavaScript projects get api.services.js only. TypeScript projects get both api.types.ts and api.services.ts.