Skip to main content

Parameters

string
required
The definition name. Must be an identifier.
readonly string[]
required
External input names, inferred as literal types.
readonly string[]
required
External output names, inferred as literal types. Must not repeat any input name.
(builder: CircuitBuilder) => void
required
A synchronous callback that adds parts and wires them. It runs immediately, exactly once, and its result is validated before circuit() returns.

Returns

A frozen ComponentDefinition with kind: "composite".

CircuitBuilder

Every wiring call reads destination ← source.
{ [name]: SourcePort }
The circuit’s own inputs. Use them as sources for the parts you add.
(definition, name?, inputs?) => ComponentInstance
Adds a part made from any definition, and wires the inputs listed in inputs, an object like { a: source, b: source }. Inputs you leave out must be wired later with feed. Without name, a deterministic name <Definition>#<n> is generated, and the inputs object moves to the second argument: add(NOT, { a: inputs.a }). The returned part exposes outputs (sources) and inputs (only for feed).
(input: SinkPort, source: SourcePort) => void
Wires an input of a part you already added. This is how feedback loops are built, because the source can be a part added after the one it feeds.
(name: O, source: SourcePort) => void
Drives one of the circuit’s own outputs from a source. Each output must be driven exactly once.

Example

With feedback:

Errors

Every error is a CircuitError whose message is prefixed with the circuit name.