mobx-state-tree
Version:
Opinionated, transactional, MobX powered state container
59 lines (58 loc) • 1.84 kB
TypeScript
import { ISimpleType, IType } from "../../internal";
/**
* `types.identifier` - Identifiers are used to make references, lifecycle events and reconciling works.
* Inside a state tree, for each type can exist only one instance for each given identifier.
* For example there couldn't be 2 instances of user with id 1. If you need more, consider using references.
* Identifier can be used only as type property of a model.
* This type accepts as parameter the value type of the identifier field that can be either string, number or bigint.
*
* Example:
* ```ts
* const Todo = types.model("Todo", {
* id: types.identifier,
* title: types.string
* })
* ```
*
* @returns
*/
export declare const identifier: ISimpleType<string>;
/**
* `types.identifierNumber` - Similar to `types.identifier`. This one will serialize from / to a number when applying snapshots
*
* Example:
* ```ts
* const Todo = types.model("Todo", {
* id: types.identifierNumber,
* title: types.string
* })
* ```
*
* @returns
*/
export declare const identifierNumber: ISimpleType<number>;
/**
* `types.identifierBigint` - Similar to `types.identifier`. Snapshots serialize to string (JSON-safe) and deserialize from string, number or bigint.
*
* Example:
* ```ts
* const Todo = types.model("Todo", {
* id: types.identifierBigint,
* title: types.string
* })
* ```
*
* @returns
*/
export declare const identifierBigint: IType<bigint | string | number, string, bigint>;
/**
* Returns if a given value represents an identifier type.
*
* @param type
* @returns
*/
export declare function isIdentifierType(type: unknown): type is typeof identifier | typeof identifierNumber | typeof identifierBigint;
/**
* Valid types for identifiers.
*/
export type ReferenceIdentifier = string | number | bigint;