Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
U

untypeable

> 编程语言
Open source

Get type-safe access to any API, with a zero-bundle size option.

383 stars0 likes1 views
WebsiteGitHub

About

Get type-safe access to any API, with a zero-bundle size option.

Untypeable

Get type-safe access to any API, with a zero-bundle size option.

The Problem

If you're lucky enough to use tRPC, GraphQL, or OpenAPI, you'll be able to get type-safe access to your API - either through a type-safe RPC or codegen.

But what about the rest of us?

What do you do if your API has no types?

Solution

Enter untypeable - a first-class library for typing API's you don't control.

  • Get autocomplete on your entire API, without needing to set up a single generic function.
  • Simple to configure, and extremely flexible.
  • Choose between two modes:
  • Zero bundle-size: use import type to ensure untypeable adds nothing to your bundle.
  • Strong types: integrates with libraries like Zod to add runtime safety to the types.
  • ✨ Keep things organized with helpers for merging and combining your config.
  • ❤️ You bring the fetcher, we bring the types. There's no hidden magic.

Quickstart

npm i untypeable

…

SWAPI Example

We've added a full example of typing swapi.dev.

Zero-bundle mode

You can set up untypeable to run in zero-bundle mode. This is great for situations where you trust the API you're calling, but it just doesn't have types.

To set up zero-bundle mode, you'll need to:

  1. Define your router in a file called router.ts.
  2. Export the type of your router: export type MyRouter = typeof router;
typescript
// router.ts

import { initUntypeable } from "untypeable";

const u = initUntypeable();

type User = {
  id: string;
  name: string;
};

const router = u.router({
  "/user": u.input().output(),
});

export type MyRouter = typeof router;
  1. In a file called client.ts, import createTypeLevelClient from untypeable/type-level-client.
typescript
// client.ts

import { createTypeLevelClient } from "untypeable/client";
import type { MyRouter } from "./router";

export const client = createTypeLevelClient(() => {
  // your implementation...
});

How does this work?

This works because createTypeLevelClient is just an identity function, which directly returns the function you pass it. Most modern bundlers are smart enough to collapse identity functions and erase type imports, so you end up with:

typescript
// client.ts

export const client = () => {
  // your implementation...
};

Runtime-safe mode

Sometimes, you just don't trust the API you're calling. In those situations, you'll often like to validate the data you get back.

untypeable offers first-class integration with Zod. You can pass a Zod schema to u.input and u.output to ensure that these values are validated with Zod.

typescript
import { initUntypeable, createSafeClient } from "untypeable";
import { z } from "zod";

const u = initUntypeable();

const router = u.router({
  "/user": u
    .input(
      z.object({
        id: z.string(),
      }),
    )
    .output(
      z.object({
        id: z.string(),
        name: z.string(),
      }),
    ),
});

export const client = createSafeClient(router, () => {
  // Implementation...
});

Now, every call made to client will have its input and output verified by the zod schemas passed.

Configuration & Arguments

untypeable lets you be extremely flexible with the shape of your router.

Each level of the router corresponds to an argument that'll be passed to your client.

typescript
// A router that looks like this:
const router = u.router({
  github: {
    "/repos": {
      GET: u.output(),
      POST: u.output(),
    },
  },
});

const client = createTypeLevelClient(() => {});

// Will need to be called like this:
client("github", "/repos", "POST");

You can set up this argument structure using the methods below:

.pushArg

Using the .pushArg method when we initUntypeable lets us add new arguments that must be passed to our client.

…

You can call this as many times as you want!

typescript
const u = initUntypeable()
  .pushArg()
  .pushArg();

const router = u.router({
  "/": {
    GET: {
      foo: u.output,
    },
  },
});

.unshiftArg

You can also add an argument at the start using .unshiftArg. This is useful for when you want to add different base endpoints:

typescript
const u = initUntypeable().unshiftArg();

const router = u.router({
  github: {
    "/repos": u.output(),
  },
});

.args

Useful for when you want to set the args up manually:

typescript
const u = initUntypeable().args();

const router = u.router({
  "any-string": {
    "any-other-string": {
      "yet-another-string": u.output(),
    },
  },
});

Organizing your routers

.add

You can add more detail to a router, or split it over multiple calls, by using router.add.

typescript
const router = u
  .router({
    "/": u.output(),
  })
  .add({
    "/user": u.output(),
  });

.merge

You can merge two routers together using router.merge. This is useful for when you want to combine multiple routers (perhaps in different modules) together.

typescript
import { userRouter } from "./userRouter";
import { postRouter } from "./postRouter";

export const baseRouter = userRouter.merge(postRouter);

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言