export type Objectish = AnyObject | AnyArray | AnyMap | AnySet; export type AnyObject = { [key: string]: unknown; }; export type AnyArray = readonly unknown[]; export type AnySet = ReadonlySet; export type AnyMap = ReadonlyMap; export type DefinedArray = readonly defined[]; export type DefinedSet = ReadonlySet; export type DefinedMap = ReadonlyMap; type PrimitiveType = number | string | boolean; type AtomicObject = Callback | Promise; /** * If the lib "ES2015.Collection" is not included in tsconfig.json, * types like ReadonlyArray, WeakMap etc. fall back to `any` (specified nowhere) * or `{}` (from the node types), in both cases entering an infinite recursion in * pattern matching type mappings * This type can be used to cast these types to `void` in these cases. */ type IfAvailable = true | false extends (T extends never ? true : false) ? Fallback : keyof T extends never ? Fallback : T; /** * These should also never be mapped but must be tested after regular Map and * Set */ type WeakReferences = IfAvailable> | IfAvailable>; type MutableObject = { -readonly [K in keyof T]: Mutable; }; /**@alias Draft in rbxts/immut */ export type Mutable = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends ReadonlyMap ? Map, Mutable> : T extends ReadonlySet ? Set> : T extends WeakReferences ? T : T extends object ? MutableObject : T; type ImmutableObject = { -readonly [K in keyof T]: Mutable; }; export type Immutable = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends ReadonlyMap ? ReadonlyMap, Immutable> : T extends ReadonlySet ? ReadonlySet> : T extends WeakReferences ? T : T extends object ? ImmutableObject : T; type Underfined = { [P in keyof T]: P extends undefined ? T[P] : never; }; type FilterFlags = { [key in keyof Base]: Base[key] extends Condition ? key : never; }; type AllowedNames = FilterFlags[keyof Base]; type SubType = Pick>; export type OptionalKeys = Exclude, never>>>; export type MakeOnlyOptionalKeys = { [key in OptionalKeys]: T[key]; }; export declare namespace TableTools { /** * clones the immutable data and executes the function with draft as argument * @param data data to be cloned * @param callback draft is a clone of the data with readonly flag removed * @returns new changed copy of data (draft) */ export function CopyData(data: Data, callback: (draft: Mutable) => void): Data; export function DeepCopyData(data: Data, callback?: (draft: Mutable) => void): Data; export function FillOutDefaults(data: Partial, default_data: T): T & Partial; type GetKeyType = T extends Map ? K : T extends ReadonlyMap ? K : never; type GetValueType = T extends Map ? V : T extends ReadonlyMap ? V : never; /**returns the keys of the map */ export function GetKeys(map: T): GetKeyType[]; /**returns the values of the map */ export function GetValues(map: T): GetValueType[]; export function IsArray(data: object): boolean; export function ExtractElementsFromRecursiveData(data: Data, check: (element: defined, key: defined, taken_elements: Array, data: Data) => boolean, ignore_table_if_added?: boolean): defined[]; export function Filter(map: ReadonlyMap, check: (value: V, key: K, map: ReadonlyMap) => boolean): Map; /**@returns first element from the map [key, value] */ export function GetFirst(map: T): LuaTuple<[defined, defined]> | undefined; export function GetRandomKey(map: T): GetKeyType; export function GetRandomValue(map: T): GetValueType; export function GetOrCreate, V = GetValueType>(map: Map, key: K, create_callback: (key: K, map: Map) => V): NonNullable; export function Find(map: ReadonlyMap, check: (element: V, key: K, map: ReadonlyMap) => boolean): V | undefined; export function FindKey(map: ReadonlyMap, check: (element: V, key: K, map: ReadonlyMap) => boolean): K | undefined; export function Includes(map: ReadonlyMap, check: (element: V, key: K, map: ReadonlyMap) => boolean): boolean; export function KeyOf(map: ReadonlyMap, seached_value: V): K | undefined; export function ToPairs(map: ReadonlyMap): [K, V][]; export function MapToArray(map: ReadonlyMap, selector: (key: K, value: V, map: ReadonlyMap) => Q): Q[]; export function MapToArrayFiltered(map: ReadonlyMap, selector: (key: K, value: V, map: ReadonlyMap) => Q | void): Q[]; /** * * @param new_map * @param old_map * @returns keys that dont exist in new_map, but exist in old_map */ export function GetMissingKeys(new_map: ReadonlyMap, old_map: ReadonlyMap): K[]; /** * * @param new_map * @param old_map * @returns keys that exist in new_map, but dont exist in old_map */ export function GetNewKeys(new_map: ReadonlyMap, old_map: ReadonlyMap): K[]; /** * * @param new_map * @param old_map * @param selector * @param ignore_missing_or_new_keys * @returns keys of different values */ export function GetDifferentValueKeys(new_map: ReadonlyMap, old_map: ReadonlyMap, selector?: (value_1: V1, value_2: V2, key_1: K, key_2: K, map_1: ReadonlyMap, map_2: ReadonlyMap) => boolean, ignore_missing_or_new_keys?: boolean): K[]; /** * maps the map to the new map * @param map map * @param selector => [new_key, new_value] * @returns mapped map from map */ export function MapToNew(map: ReadonlyMap, selector: (key: K0, value: V0, map: ReadonlyMap) => [K1, V1]): Map; /** * maps the map to the new map, if no value was returned will filter the value * @param map map * @param selector => [new_key, new_value] * @returns mapped filtered map from map */ export function MapFiltered(map: ReadonlyMap, selector: (key: K0, value: V0, map: ReadonlyMap) => void | undefined | [K1, V1]): Map; export {}; } export {};