UNPKG

2.16 kBTypeScriptView Raw
1import { IObservableArray } from "mobx";
2import { ExtractCSTWithSTN, IAnyType, IHooksGetter, IType } from "../../internal";
3/** @hidden */
4export interface IMSTArray<IT extends IAnyType> extends IObservableArray<IT["Type"]> {
5 push(...items: IT["Type"][]): number;
6 push(...items: ExtractCSTWithSTN<IT>[]): number;
7 concat(...items: ConcatArray<IT["Type"]>[]): IT["Type"][];
8 concat(...items: ConcatArray<ExtractCSTWithSTN<IT>>[]): IT["Type"][];
9 concat(...items: (IT["Type"] | ConcatArray<IT["Type"]>)[]): IT["Type"][];
10 concat(...items: (ExtractCSTWithSTN<IT> | ConcatArray<ExtractCSTWithSTN<IT>>)[]): IT["Type"][];
11 splice(start: number, deleteCount?: number): IT["Type"][];
12 splice(start: number, deleteCount: number, ...items: IT["Type"][]): IT["Type"][];
13 splice(start: number, deleteCount: number, ...items: ExtractCSTWithSTN<IT>[]): IT["Type"][];
14 unshift(...items: IT["Type"][]): number;
15 unshift(...items: ExtractCSTWithSTN<IT>[]): number;
16}
17/** @hidden */
18export interface IArrayType<IT extends IAnyType> extends IType<IT["CreationType"][] | undefined, IT["SnapshotType"][], IMSTArray<IT>> {
19 hooks(hooks: IHooksGetter<IMSTArray<IAnyType>>): IArrayType<IT>;
20}
21/**
22 * `types.array` - Creates an index based collection type who's children are all of a uniform declared type.
23 *
24 * This type will always produce [observable arrays](https://mobx.js.org/api.html#observablearray)
25 *
26 * Example:
27 * ```ts
28 * const Todo = types.model({
29 * task: types.string
30 * })
31 *
32 * const TodoStore = types.model({
33 * todos: types.array(Todo)
34 * })
35 *
36 * const s = TodoStore.create({ todos: [] })
37 * unprotect(s) // needed to allow modifying outside of an action
38 * s.todos.push({ task: "Grab coffee" })
39 * console.log(s.todos[0]) // prints: "Grab coffee"
40 * ```
41 *
42 * @param subtype
43 * @returns
44 */
45export declare function array<IT extends IAnyType>(subtype: IT): IArrayType<IT>;
46/**
47 * Returns if a given value represents an array type.
48 *
49 * @param type
50 * @returns `true` if the type is an array type.
51 */
52export declare function isArrayType<Items extends IAnyType = IAnyType>(type: IAnyType): type is IArrayType<Items>;