Absence
type| Package | @formscript/types |
|---|---|
| Specification | 5, 5.2, 5.3, 5.5 |
| Depends on | ast |
@formscript/types
The type system of §5 of the specification: the lattice, the coercion table, the absence model and the field state.
The lattice
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":
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.
ANY
re-exportApplicability
typearrayOf
re-exportcanCoerce
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
interfaceCoercionKind
type
The permitted coercions are exactly four (Spec-5.16).
CoercionResult
typeCOERCIONS
constConstraintOutcome
interfaceContent
typecontentOf
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
constderiveValidity
function
Derives a field's validity from its three stored axes and its constraint outcomes (Spec-5.2). Validity is never stored.
describeState
functiondescribeType
re-exportdominantAbsence
function
`inapplicable` dominates `null` when the two meet (Spec-5.18).
FAILED
constFieldState
interfaceINAPPLICABLE
constINITIAL_STATE
constisAbsent
functionisAssignable
re-exportisEmpty
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
functionisSubtype
re-exportisUnknown
functionjoin
re-exportmayShowViolation
function
Whether a violation may be shown yet (Spec-5.7).
PASSED
constreadValue
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-exportTypeBound
interfaceTypeDescriptor
interfaceTypeName
typetypeOfLiteral
re-exporttypeRefToDescriptor
re-exportUNKNOWN
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