FS FormScript
Package@formscript/types
Specification5, 5.2, 5.3, 5.5
Depends onast

@formscript/types

The type system of §5 of the specification: the lattice, the coercion table, the absence model and the field state.

The lattice

ts
import { isAssignable, isSubtype, join, scalar } from '@formscript/types';

isSubtype(scalar('integer'), scalar('number'));   // true
isAssignable(scalar('any'), scalar('boolean'));   // true — `any` fits anywhere
join(scalar('string'), scalar('number'));          // `any`

The lattice is deliberately small. string is a subtype of display; no other type is a subtype of any other, and display is not a subtype of string.

Coercion

Four conversions are permitted (§5.3) — string → number, string → date, number → integer, integer → number. Everything else is an error. canCoerce answers the question; coerce performs the conversion and returns a failure rather than throwing.

Absence

null and inapplicable are distinct first-class values (§5.5), and neither is the same thing as "empty":

ts
import { UNKNOWN, INAPPLICABLE, isAbsent, isEmpty } from '@formscript/types';

isEmpty is about content — an empty string is empty. isAbsent is about absence — an unknown or inapplicable value is absent.

Field state

A field's state has three axes (§5.2): content, applicability and validity. deriveValidity folds the constraint outcomes into it, and satisfiesRequired answers the question the required constraint asks.

Public API

42 exported symbols.

Absence type
ANY re-export
Applicability type
arrayOf re-export
canCoerce function

Whether the conversion is one of the four permitted coercions.

coerce function

Performs a coercion. A coercion that fails yields the error value rather than throwing (Spec-5.18) — the caller receives `ok: false` and raises `E-EVAL-06` /…

Coercion interface
CoercionKind type

The permitted coercions are exactly four (Spec-5.16).

CoercionResult type
COERCIONS const
ConstraintOutcome interface
Content type
contentOf function

The content of a field holding `value` (Spec-5.4).

DEFAULT_REPEAT_MAX const

The default maximum number of rows in a `repeat` that declares no `max` (Spec-7.9). A repeat's `max` is the iteration bound the cost model uses (Spec-6.6), s…

DEFERRED const
deriveValidity function

Derives a field's validity from its three stored axes and its constraint outcomes (Spec-5.2). Validity is never stored.

describeState function
describeType re-export
dominantAbsence function

`inapplicable` dominates `null` when the two meet (Spec-5.18).

FAILED const
FieldState interface
INAPPLICABLE const
INITIAL_STATE const
isAbsent function
isAssignable re-export
isEmpty function

Whether a value is `empty` (Spec-5.4): `null`, a zero-length string, an empty array, or an empty choice. `0` and `false` are **not** empty.

isInapplicable function
isSubtype re-export
isUnknown function
join re-export
mayShowViolation function

Whether a violation may be shown yet (Spec-5.7).

PASSED const
readValue function

The value an expression sees when it reads a field (Spec-5.8).

satisfiesRequired function

A field's declared type participates in the empty check for `required`.

scalar re-export
TypeBound interface
TypeDescriptor interface
TypeName type
typeOfLiteral re-export
typeRefToDescriptor re-export
UNKNOWN const

The two absence values (Spec-5.22). `null` means *unknown*; `inapplicable` means *not applicable*. They are distinct first-class values and neither equals an…

Validity type