Compile-time shapes exported for advanced usage.
Typebox is compile-time only. Types vanish at runtime, and there is no runtime schema object. All public types are re-exported from the package entry with export type *, so you can import any of the names below.
import type { ContractFn, GuardVerdict, StateHandle } from '@neabyte/typebox'The atom. A single-input contract function from an input shape to an output shape. See Define for how contracts are built.
type ContractFn = (input: never) => unknownThe first parameter type of a contract.
type ContractInput<ContractType extends ContractFn> = Parameters<ContractType>[0]A contract function or a stateful base entry. This is the value type of a contract map.
type ContractEntry = ContractFn | StatefulBaseA record mapping names to contract entries. This is the input to Loader.
type ContractMap = Record<string, ContractEntry>See Validation for how these are used at runtime.
A synchronous guard for a contract's input.
type GuardFn<ContractType extends ContractFn> = (input: ContractInput<ContractType>) => GuardVerdictOne guard or a list of guards for a contract.
type GuardInput<ContractType extends ContractFn> =
| GuardFn<ContractType>
| readonly GuardFn<ContractType>[]A guard result as a pass flag or a set of reasons.
type GuardVerdict = true | string | readonly string[]See State for the runtime behavior of these shapes.
A fully typed stateful contract that holds an initial state and a step reducer. Built by Define.state.
The live form of a stateful contract. Call it to advance state, and call get() to read the current immutable value.
interface StateHandle<ValueType, PayloadType> {
(...args: [PayloadType] extends [NoPayload] ? [] : [payload: PayloadType]): ValueType
get(): DeepImmutable<ValueType>
}A reducer that advances state by one step. Its arity decides whether a payload is required.
type StepFn<ValueType, ArgsType extends [] | [unknown]> = (
state: ValueType,
...args: ArgsType
) => ValueTypeThe payload type read from a step's argument tuple. A two-argument step yields its payload, and a one-argument step yields the no-payload marker.
The public stateful builder API, exposed as Define.state.
interface StatefulApi {
state<ValueType, ArgsType extends [] | [unknown]>(
initialState: ValueType,
stepFn: StepFn<ValueType, ArgsType>
): StatefulContract<ValueType, PayloadOf<ArgsType>>
}The facade returned by Loader. Every key maps to its activated entry.
type LoadedFacade<ContractMapType extends ContractMap> = {
readonly [Key in keyof ContractMapType]: LiveEntry<ContractMapType[Key]>
}The activated entry for one map entry. A stateful entry becomes a StateHandle, and a contract becomes a plain callable with normalized output.
Normalizes a contract output for the facade. A PromiseLike output is flattened with Awaited so the value is reached with one await.
type UnwrapOutput<OutputType> = OutputType extends PromiseLike<unknown>
? Promise<Awaited<OutputType>>
: OutputTypeA recursively immutable version of a type. Functions pass through, Map and Set become their readonly forms with immutable members, and objects become deeply readonly. Used for StateHandle.get() reads.
type DeepImmutable<SourceType> = SourceType extends (...args: never[]) => unknown ? SourceType
: SourceType extends ReadonlyMap<infer KeyType, infer ValueType>
? ReadonlyMap<KeyType, DeepImmutable<ValueType>>
: SourceType extends ReadonlySet<infer ValueType> ? ReadonlySet<DeepImmutable<ValueType>>
: SourceType extends object
? { readonly [Key in keyof SourceType]: DeepImmutable<SourceType[Key]> }
: SourceTypeAn object with an optional then property. Used to detect async guards at runtime.
type ThenableLike = { readonly then?: unknown }