Schemas

Status: implemented

A schema is an ordinary immutable value. A Type is one of:

  • Const, used directly as its own schema:
    • Primitive (null, undefined, true, 42, 'hello', 7n), which admits exactly itself (constants)
    • Tuple (readonly[schema, ...]), which reads each element by position
    • Struct ({ key: schema, ... }), which reads each declared property
  • Thunk (() => Info), a lazy schema for the built-ins and for recursive types

The built-in schemas are all thunks: functions that return an Info descriptor. Nullary schemas (boolean, string, etc.) return a single-tag tuple; unary schemas (array, record) return a tag and the inner type.

SchemaReturnsAdmitsPage
boolean['boolean']any booleanprimitives
number['number']any numberprimitives
string['string']any stringprimitives
bigint['bigint']any bigintprimitives
unknown['unknown']any DataJS valueprimitives
option['option']nothing but absence: or(option, t) is a member that may be left outabsence
or(...ts)['or', ...ts]a value any member admits; never is or()unions
array(t)['array', t]readonly Ts<t>[]arrays and records
record(t)['record', t]{ readonly[K in string]?: Ts<t> }arrays and records
rest(c, r)['rest', c, r]c's members, and only members of r besidesopen containers
open(c)['rest', c, unknown]c's members, and anything elseopen containers

Pages

Planned

These TypeScript type forms have no schema yet:

  • function types (668)
  • a string type that excludes some values (excluded string values)
  • intersections, which no todo proposes yet

Reference

Where it is implemented

The constructors in module.f.mjs and the types in types.ts.

Emergent Testing

Idle. Press Run to start the suite.

  • ./arrays-and-records/proof.f.mjs
  • ./closed-containers/proof.f.mjs
  • ./constants/proof.f.mjs
  • ./open-containers/proof.f.mjs
  • ./option/proof.f.mjs
  • ./primitives/proof.f.mjs
  • ./proof.f.mjs
  • ./recursion/proof.f.mjs
  • ./unions/proof.f.mjs