Skip to content

typebox#2

Draft
mmkal wants to merge 4 commits into
mainfrom
mmkal/26/05/08/typebox
Draft

typebox#2
mmkal wants to merge 4 commits into
mainfrom
mmkal/26/05/08/typebox

Conversation

@mmkal
Copy link
Copy Markdown
Owner

@mmkal mmkal commented May 8, 2026

Summary

Adds a TypeBox-specific entrypoint for TypeScript-string cases and introduces clearer throwing terminals for matcher chains.

Consumers who install the optional typebox peer can import from schematch/typebox and use TypeBox Script(...) strings directly in .case(...). The root schematch entrypoint stays TypeBox-free, so projects that do not install typebox do not resolve TypeBox types.

import {match} from 'schematch/typebox'

const matcher = match
  .case(`string`, s => s.substring(2))
  .case(`[number, number]`, ([x, y]) => x + y)
  .case(`{ foo: string; bar: number }`, obj => obj.foo + obj.bar.toFixed(2))
  .exhaustive()

matcher('hello') // "llo"
matcher([1, 2]) // 3
matcher({foo: 'x', bar: 1.2345}) // "x1.23"
match({ x: 1 }) // type error

TypeBox strings are parsed with Script(...), compiled lazily with TypeBox's schema compiler, and TypeBox validation errors are surfaced through MatchError / Standard Schema issues.

API Notes

  • Adds schematch/typebox with a named match export.
  • Keeps TypeBox overloads out of the root schematch entrypoint.
  • Adds TypeBox string .case(...) overloads for inline and reusable matchers in the TypeBox entrypoint.
  • Adds .orThrow() as the readable equivalent of .default(match.throw).
  • Adds .exhaustive() as the readable equivalent of .default<never>(match.throw).
  • Keeps .default(...) available for fallback handlers and values.

Verification

  • pnpm vitest run tests/high-level/typebox.test.ts --typecheck
  • pnpm test
  • pnpm build
  • pnpm attw

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 8, 2026

Open in StackBlitz

npm i https://pkg.pr.new/schematch@2

commit: a903258

mmkal added 2 commits May 8, 2026 16:22
Add schematch/typebox as a named-match entrypoint so TypeBox Script string overloads only load for consumers who opt into the optional peer dependency.

Remove TypeBox configuration and overloads from the root match export, and update the TypeBox examples/tests to import {match} from schematch/typebox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant