TinyBase logoTinyBase β

CellSchema

The CellSchema type describes what values are allowed for each Cell in a Table.

{
  type: "string";
  default?: string;
} | {
  type: "number";
  default?: number;
} | {
  type: "boolean";
  default?: boolean;
}

A CellSchema specifies the type of the Cell (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 that Cell will always be present in a Row.

If the default value is not provided (or its type is incorrect), the Cell may be missing from the Row, but when present you can be guaranteed it is of the correct type.

Example

When applied to a Store, this CellSchema ensures a boolean Cell is always present, and defaults it to false.

import type {CellSchema} from 'tinybase';

export const requiredBoolean: CellSchema = {
  type: 'boolean',
  default: false,
};

Since

v1.0.0