PayKitv0.1 beta

TypeScript

Type inference, plan ID narrowing, and compile-time safety.

PayKit is built TypeScript-first. Plan IDs, feature IDs, and method inputs are inferred from your configuration, so you don't need any manual type definitions.

Inferred plan and feature IDs

When you pass products to createPayKit, all methods narrow their ID parameters to only accept valid values. Typos become compile errors.

paykit.ts
// Types are inferred from your products
export const paykit = createPayKit({
  products: [free, pro, ultra],
  // ...
});

// planId only accepts "free" | "pro" | "ultra"
await paykit.subscribe({ customerId: "user_123", planId: "pro" });

// featureId only accepts "messages" | "pro_models" | "priority_support"
await paykit.check({ customerId: "user_123", featureId: "messages" });

Passing an invalid ID fails at compile time:

// Type error: "typo" is not assignable to "free" | "pro" | "ultra"
await paykit.subscribe({ customerId: "user_123", planId: "typo" });

Your editor's autocomplete also knows every valid plan and feature ID across the whole app.

The $infer helper

paykit.$infer exposes the inferred union types so you can use them elsewhere in your app without re-declaring them.

type PlanId = typeof paykit.$infer.planId;
// => "free" | "pro" | "ultra"

type FeatureId = typeof paykit.$infer.featureId;
// => "messages" | "pro_models" | "priority_support"

Use these anywhere you need to accept or return a plan or feature ID: form props, route params, database columns, and so on.

Client type safety

The PayKit client SDK inherits the server instance's types via createPayKitClient<typeof paykit>(). No server code is bundled; only the type is imported.

src/lib/paykit-client.ts
// Client inherits server types
import type { paykit } from "@/server/paykit";

const client = createPayKitClient<typeof paykit>();
await client.subscribe({ planId: "pro" }); // ✓ type-safe

Plan IDs are validated on the client too. Passing an invalid planId is a compile error regardless of where you call it.

Product arrays

Pass products to createPayKit as an array of values returned by plan(...).

import { free, pro, ultra } from "./products";

export const paykit = createPayKit({
  products: [free, pro, ultra],
  // ...
});

This preserves full plan and feature ID inference.

On this page