> hypequery

Type Helpers

TypeScript helpers for the current hypequery query and serve APIs.

Type Helpers

These are the most useful type helpers in the current initServe / query({ ... }) / serve({ queries }) path.

InferApiType

Use InferApiType to extract the client-safe API shape from an exported api.

import { InferApiType } from '@hypequery/serve';
import { api } from '@/analytics/queries';

type Api = InferApiType<typeof api>;

The inferred type maps each query key to:

type Api = {
  activeUsers: {
    input: { limit?: number };
    output: Array<{
      id: string;
      email: string;
      created_at: string;
    }>;
  };
};

This is the type you typically pass into @hypequery/react.

InferQueryInput

Extract the input type for one query key from an exported api or query map.

import type { InferQueryInput } from '@hypequery/serve';
import { api } from '@/analytics/queries';

type ActiveUsersInput = InferQueryInput<typeof api, 'activeUsers'>;

InferQueryOutput

Extract the output type for one query key.

import type { InferQueryOutput } from '@hypequery/serve';
import { api } from '@/analytics/queries';

type ActiveUsersOutput = InferQueryOutput<typeof api, 'activeUsers'>;

InferQueryResult

Extract the resolved return type of the query resolver.

import type { InferQueryResult } from '@hypequery/serve';
import { api } from '@/analytics/queries';

type ActiveUsersResult = InferQueryResult<typeof api, 'activeUsers'>;

Query Input / Output Inference

When you define a query with Zod schemas, TypeScript infers both input and output automatically:

const activeUsers = query({
  input: z.object({
    limit: z.number().min(1).max(100).default(10),
  }),
  output: z.array(z.object({
    id: z.string(),
    email: z.string(),
  })),
  query: async ({ ctx, input }) => {
    return ctx.db.table('users').select(['id', 'email']).limit(input.limit).execute();
  },
});

Inside the resolver:

  • input is inferred from input
  • the return value is checked against output

Resolver Types

The runtime also exports resolver/context helpers:

import type { QueryResolverArgs, QueryRuntimeContext } from '@hypequery/serve';
  • QueryResolverArgs<TInput, TContext, TAuth>
  • QueryRuntimeContext<TContext, TAuth>

Query Builder Types

The builder itself remains fully typed from your generated schema:

import { createQueryBuilder } from '@hypequery/clickhouse';
import type { IntrospectedSchema } from './schema';

const db = createQueryBuilder<IntrospectedSchema>({ client });

That gives you:

  • typed table names
  • typed column names
  • typed result shapes
  • typed operators

React Hook Types

InferApiType works directly with createHooks:

import { createHooks } from '@hypequery/react';
import { InferApiType } from '@hypequery/serve';
import { api } from '@/analytics/queries';

type Api = InferApiType<typeof api>;

export const { useQuery, useMutation } = createHooks<Api>({
  baseUrl: '/api',
});

See Also

On this page