Skip to content

Instantly share code, notes, and snippets.

@DubiousS
Last active October 22, 2019 03:11
Show Gist options
  • Save DubiousS/95cf868c477e56cb65edb002349b3ac8 to your computer and use it in GitHub Desktop.
Save DubiousS/95cf868c477e56cb65edb002349b3ac8 to your computer and use it in GitHub Desktop.
export interface IImmutableMap<Model, State = Model> extends Immutable.Map<any, any> {
toObject(): State;
get<K extends keyof State>(key: K): State[K];
getIn<K extends keyof State>(searchKeyPath: [K], notSetValue?: any): State[K];
getIn<
K extends keyof Model,
K2 extends keyof Model[K]
>(searchKeyPath: [K, K2], notSetValue?: any): Model[K][K2];
set<K extends keyof State>(key: K, value: State[K]): this;
setIn<K extends keyof State>(keyPath: [K], value: any): this;
setIn<
K extends keyof Model,
K2 extends keyof Model[K],
>(keyPath: [K, K2], value: any): this;
withMutations(mutator: (mutable: this) => any): this;
update<K extends keyof State>(
key: K,
notSetValue: State[K],
updater: (value: State[K]) => State[K],
): this;
update<K extends keyof State>(
key: K,
updater: (value: State[K]) => State[K],
): this;
update<R>(updater: (value: this) => R): R;
}
export interface IImmutableList<T> extends Immutable.List<T> {
toJS(): T[];
set(index: number, value: T): this;
get<K extends keyof T>(key: K): T;
filter(
predicate: (value: T, index: number, iter: this) => boolean,
context?: T,
): this;
withMutations(mutator: (mutable: this) => any): this;
push(...values: T[]): this;
unshift(...values: T[]): this;
reduce<R>(
reducer: (reduction: R, value: T, key: number, iter: this) => R,
initialReduction: R,
context?: T,
): R;
reduce<R>(
reducer: (reduction: T | R, value: T, key: number, iter: this) => R,
): R;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment