TypeBox schemas with Value.Check and Value.Parse: working versions (tested 2026-10-15)
Define TypeBox schemas with constraints and transforms, then use Value.Check, Value.Errors and Value.Parse for typed validation without a runtime compiler.
passed2 passed · 0 failed2026-10-15 16:06 UTC- Status
- passed
- Last passed
- 2026-10-15 16:06 UTC
- Tests
- 2 / 2
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
@sinclair/typebox@0.34.52@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38764699834
The code
Exactly the files that passed. Your agent can pull them with get_recipe("typebox-value-check") (install), or see them on GitHub.
package.json
{
"name": "typebox-value-check",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"@sinclair/typebox": "0.34.52"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/schema.ts
import { Type, type Static } from "@sinclair/typebox";
import { Value } from "@sinclair/typebox/value";
export const CreateUser = Type.Object({
email: Type.String({ format: "email" }),
name: Type.String({ minLength: 1, maxLength: 80 }),
age: Type.Optional(Type.Integer({ minimum: 13 })),
tags: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 5 })),
}, { additionalProperties: false });
export type CreateUser = Static<typeof CreateUser>;
export function parseUser(input: unknown) {
// TypeBox format checks need FormatRegistry for email; use pattern instead for offline purity
const Schema = Type.Object({
email: Type.String({ pattern: "^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$" }),
name: Type.String({ minLength: 1, maxLength: 80 }),
age: Type.Optional(Type.Integer({ minimum: 13 })),
tags: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { maxItems: 5 })),
}, { additionalProperties: false });
if (!Value.Check(Schema, input)) {
return {
ok: false as const,
errors: [...Value.Errors(Schema, input)].map((e) => ({ path: e.path, message: e.message })),
};
}
return { ok: true as const, data: Value.Parse(Schema, input) };
}
test/schema.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { parseUser } from "../src/schema.ts";
test("accepts valid user", () => {
const r = parseUser({ email: "[email protected]", name: "Ada", age: 30 });
assert.equal(r.ok, true);
if (r.ok) assert.equal(r.data.name, "Ada");
});
test("rejects extras and bad email", () => {
assert.equal(parseUser({ email: "nope", name: "Ada" }).ok, false);
assert.equal(parseUser({ email: "[email protected]", name: "Ada", admin: true }).ok, false);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.