ValueSchema
The ValueSchema
type describes what values are allowed for keyed Values
in a Store
.
{
type: "string";
default?: string;
} | {
type: "number";
default?: number;
} | {
type: "boolean";
default?: boolean;
}
A ValueSchema
specifies the type of the Value
(string
, boolean
, or number
), and what the default value can be when an explicit value is not specified.
If a default value is provided (and its type is correct), you can be certain that the Value
will always be present in a Store
.
If the default value is not provided (or its type is incorrect), the Value
may not be present in the Store
, but when present you can be guaranteed it is of the correct type.
Example
When applied to a Store
, this ValueSchema
ensures a boolean Value
is always present, and defaults it to false
.
import type {ValueSchema} from 'tinybase';
export const requiredBoolean: ValueSchema = {
type: 'boolean',
default: false,
};
Since
v3.0.0