[d24f17c] | 1 | /**
|
---|
| 2 | * Copyright (c) 2014-present, Facebook, Inc.
|
---|
| 3 | *
|
---|
| 4 | * This source code is licensed under the MIT license found in the
|
---|
| 5 | * LICENSE file in the root directory of this source tree.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /**
|
---|
| 9 | * This file provides type definitions for use with the Flow type checker.
|
---|
| 10 | *
|
---|
| 11 | * An important caveat when using these definitions is that the types for
|
---|
| 12 | * `Iterable.Keyed`, `Iterable.Indexed`, `Seq.Keyed`, and so on are stubs.
|
---|
| 13 | * When referring to those types, you can get the proper definitions by
|
---|
| 14 | * importing the types `KeyedIterable`, `IndexedIterable`, `KeyedSeq`, etc.
|
---|
| 15 | * For example,
|
---|
| 16 | *
|
---|
| 17 | * import { Seq } from 'immutable'
|
---|
| 18 | * import type { IndexedIterable, IndexedSeq } from 'immutable'
|
---|
| 19 | *
|
---|
| 20 | * const someSeq: IndexedSeq<number> = Seq.Indexed.of(1, 2, 3)
|
---|
| 21 | *
|
---|
| 22 | * function takesASeq<T, TS: IndexedIterable<T>>(iter: TS): TS {
|
---|
| 23 | * return iter.butLast()
|
---|
| 24 | * }
|
---|
| 25 | *
|
---|
| 26 | * takesASeq(someSeq)
|
---|
| 27 | *
|
---|
| 28 | * @flow
|
---|
| 29 | */
|
---|
| 30 |
|
---|
| 31 | /*
|
---|
| 32 | * Alias for ECMAScript `Iterable` type, declared in
|
---|
| 33 | * https://github.com/facebook/flow/blob/master/lib/core.js
|
---|
| 34 | *
|
---|
| 35 | * Note that Immutable values implement the `ESIterable` interface.
|
---|
| 36 | */
|
---|
| 37 | type ESIterable<T> = $Iterable<T,void,void>;
|
---|
| 38 |
|
---|
| 39 | declare class Iterable<K, V> extends _Iterable<K, V, typeof KeyedIterable, typeof IndexedIterable, typeof SetIterable> {}
|
---|
| 40 |
|
---|
| 41 | declare class _Iterable<K, V, KI, II, SI> {
|
---|
| 42 | static Keyed: KI;
|
---|
| 43 | static Indexed: II;
|
---|
| 44 | static Set: SI;
|
---|
| 45 |
|
---|
| 46 | static isIterable(maybeIterable: any): boolean;
|
---|
| 47 | static isKeyed(maybeKeyed: any): boolean;
|
---|
| 48 | static isIndexed(maybeIndexed: any): boolean;
|
---|
| 49 | static isAssociative(maybeAssociative: any): boolean;
|
---|
| 50 | static isOrdered(maybeOrdered: any): boolean;
|
---|
| 51 |
|
---|
| 52 | equals(other: Iterable<K,V>): boolean;
|
---|
| 53 | hashCode(): number;
|
---|
| 54 | get(key: K): V;
|
---|
| 55 | get<V_>(key: K, notSetValue: V_): V|V_;
|
---|
| 56 | has(key: K): boolean;
|
---|
| 57 | includes(value: V): boolean;
|
---|
| 58 | contains(value: V): boolean;
|
---|
| 59 | first(): V;
|
---|
| 60 | last(): V;
|
---|
| 61 |
|
---|
| 62 | getIn<T>(searchKeyPath: ESIterable<any>, notSetValue: T): T;
|
---|
| 63 | getIn<T>(searchKeyPath: ESIterable<any>): T;
|
---|
| 64 | hasIn(searchKeyPath: ESIterable<any>): boolean;
|
---|
| 65 |
|
---|
| 66 | toJS(): any;
|
---|
| 67 | toArray(): V[];
|
---|
| 68 | toObject(): { [key: string]: V };
|
---|
| 69 | toMap(): Map<K,V>;
|
---|
| 70 | toOrderedMap(): Map<K,V>;
|
---|
| 71 | toSet(): Set<V>;
|
---|
| 72 | toOrderedSet(): Set<V>;
|
---|
| 73 | toList(): List<V>;
|
---|
| 74 | toStack(): Stack<V>;
|
---|
| 75 | toSeq(): Seq<K,V>;
|
---|
| 76 | toKeyedSeq(): KeyedSeq<K,V>;
|
---|
| 77 | toIndexedSeq(): IndexedSeq<V>;
|
---|
| 78 | toSetSeq(): SetSeq<V>;
|
---|
| 79 |
|
---|
| 80 | keys(): Iterator<K>;
|
---|
| 81 | values(): Iterator<V>;
|
---|
| 82 | entries(): Iterator<[K,V]>;
|
---|
| 83 |
|
---|
| 84 | keySeq(): IndexedSeq<K>;
|
---|
| 85 | valueSeq(): IndexedSeq<V>;
|
---|
| 86 | entrySeq(): IndexedSeq<[K,V]>;
|
---|
| 87 |
|
---|
| 88 | reverse(): this;
|
---|
| 89 | sort(comparator?: (valueA: V, valueB: V) => number): this;
|
---|
| 90 |
|
---|
| 91 | sortBy<C>(
|
---|
| 92 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
---|
| 93 | comparator?: (valueA: C, valueB: C) => number
|
---|
| 94 | ): this;
|
---|
| 95 |
|
---|
| 96 | groupBy<G>(
|
---|
| 97 | grouper: (value: V, key: K, iter: this) => G,
|
---|
| 98 | context?: any
|
---|
| 99 | ): KeyedSeq<G, this>;
|
---|
| 100 |
|
---|
| 101 | forEach(
|
---|
| 102 | sideEffect: (value: V, key: K, iter: this) => any,
|
---|
| 103 | context?: any
|
---|
| 104 | ): number;
|
---|
| 105 |
|
---|
| 106 | slice(begin?: number, end?: number): this;
|
---|
| 107 | rest(): this;
|
---|
| 108 | butLast(): this;
|
---|
| 109 | skip(amount: number): this;
|
---|
| 110 | skipLast(amount: number): this;
|
---|
| 111 | skipWhile(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
|
---|
| 112 | skipUntil(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
|
---|
| 113 | take(amount: number): this;
|
---|
| 114 | takeLast(amount: number): this;
|
---|
| 115 | takeWhile(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
|
---|
| 116 | takeUntil(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
|
---|
| 117 | flatten(depth?: number): /*this*/Iterable<any,any>;
|
---|
| 118 | flatten(shallow?: boolean): /*this*/Iterable<any,any>;
|
---|
| 119 |
|
---|
| 120 | filter(
|
---|
| 121 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 122 | context?: any
|
---|
| 123 | ): this;
|
---|
| 124 |
|
---|
| 125 | filterNot(
|
---|
| 126 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 127 | context?: any
|
---|
| 128 | ): this;
|
---|
| 129 |
|
---|
| 130 | reduce<R>(
|
---|
| 131 | reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
---|
| 132 | initialReduction?: R,
|
---|
| 133 | context?: any,
|
---|
| 134 | ): R;
|
---|
| 135 |
|
---|
| 136 | reduceRight<R>(
|
---|
| 137 | reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
---|
| 138 | initialReduction?: R,
|
---|
| 139 | context?: any,
|
---|
| 140 | ): R;
|
---|
| 141 |
|
---|
| 142 | every(predicate: (value: V, key: K, iter: this) => mixed, context?: any): boolean;
|
---|
| 143 | some(predicate: (value: V, key: K, iter: this) => mixed, context?: any): boolean;
|
---|
| 144 | join(separator?: string): string;
|
---|
| 145 | isEmpty(): boolean;
|
---|
| 146 | count(predicate?: (value: V, key: K, iter: this) => mixed, context?: any): number;
|
---|
| 147 | countBy<G>(grouper: (value: V, key: K, iter: this) => G, context?: any): Map<G,number>;
|
---|
| 148 |
|
---|
| 149 | find(
|
---|
| 150 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 151 | context?: any,
|
---|
| 152 | ): ?V;
|
---|
| 153 | find<V_>(
|
---|
| 154 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 155 | context: any,
|
---|
| 156 | notSetValue: V_
|
---|
| 157 | ): V|V_;
|
---|
| 158 |
|
---|
| 159 | findLast(
|
---|
| 160 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 161 | context?: any,
|
---|
| 162 | ): ?V;
|
---|
| 163 | findLast<V_>(
|
---|
| 164 | predicate: (value: V, key: K, iter: this) => mixed,
|
---|
| 165 | context: any,
|
---|
| 166 | notSetValue: V_
|
---|
| 167 | ): V|V_;
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 | findEntry(predicate: (value: V, key: K, iter: this) => mixed): ?[K,V];
|
---|
| 171 | findLastEntry(predicate: (value: V, key: K, iter: this) => mixed): ?[K,V];
|
---|
| 172 |
|
---|
| 173 | findKey(predicate: (value: V, key: K, iter: this) => mixed, context?: any): ?K;
|
---|
| 174 | findLastKey(predicate: (value: V, key: K, iter: this) => mixed, context?: any): ?K;
|
---|
| 175 |
|
---|
| 176 | keyOf(searchValue: V): ?K;
|
---|
| 177 | lastKeyOf(searchValue: V): ?K;
|
---|
| 178 |
|
---|
| 179 | max(comparator?: (valueA: V, valueB: V) => number): V;
|
---|
| 180 | maxBy<C>(
|
---|
| 181 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
---|
| 182 | comparator?: (valueA: C, valueB: C) => number
|
---|
| 183 | ): V;
|
---|
| 184 | min(comparator?: (valueA: V, valueB: V) => number): V;
|
---|
| 185 | minBy<C>(
|
---|
| 186 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
---|
| 187 | comparator?: (valueA: C, valueB: C) => number
|
---|
| 188 | ): V;
|
---|
| 189 |
|
---|
| 190 | isSubset(iter: Iterable<any, V>): boolean;
|
---|
| 191 | isSubset(iter: ESIterable<V>): boolean;
|
---|
| 192 | isSuperset(iter: Iterable<any, V>): boolean;
|
---|
| 193 | isSuperset(iter: ESIterable<V>): boolean;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | declare class KeyedIterable<K,V> extends Iterable<K,V> {
|
---|
| 197 | static <K,V>(iter?: ESIterable<[K,V]>): KeyedIterable<K,V>;
|
---|
| 198 | static <K,V>(obj?: { [key: K]: V }): KeyedIterable<K,V>;
|
---|
| 199 |
|
---|
| 200 | @@iterator(): Iterator<[K,V]>;
|
---|
| 201 | toSeq(): KeyedSeq<K,V>;
|
---|
| 202 | flip(): /*this*/KeyedIterable<V,K>;
|
---|
| 203 |
|
---|
| 204 | mapKeys<K_>(
|
---|
| 205 | mapper: (key: K, value: V, iter: this) => K_,
|
---|
| 206 | context?: any
|
---|
| 207 | ): /*this*/KeyedIterable<K_,V>;
|
---|
| 208 |
|
---|
| 209 | mapEntries<K_,V_>(
|
---|
| 210 | mapper: (entry: [K,V], index: number, iter: this) => [K_,V_],
|
---|
| 211 | context?: any
|
---|
| 212 | ): /*this*/KeyedIterable<K_,V_>;
|
---|
| 213 |
|
---|
| 214 | concat(...iters: ESIterable<[K,V]>[]): this;
|
---|
| 215 |
|
---|
| 216 | map<V_>(
|
---|
| 217 | mapper: (value: V, key: K, iter: this) => V_,
|
---|
| 218 | context?: any
|
---|
| 219 | ): /*this*/KeyedIterable<K,V_>;
|
---|
| 220 |
|
---|
| 221 | flatMap<K_, V_>(
|
---|
| 222 | mapper: (value: V, key: K, iter: this) => ESIterable<[K_,V_]>,
|
---|
| 223 | context?: any
|
---|
| 224 | ): /*this*/KeyedIterable<K_,V_>;
|
---|
| 225 |
|
---|
| 226 | flatten(depth?: number): /*this*/KeyedIterable<any,any>;
|
---|
| 227 | flatten(shallow?: boolean): /*this*/KeyedIterable<any,any>;
|
---|
| 228 | }
|
---|
| 229 |
|
---|
| 230 | declare class IndexedIterable<T> extends Iterable<number,T> {
|
---|
| 231 | static <T>(iter?: ESIterable<T>): IndexedIterable<T>;
|
---|
| 232 |
|
---|
| 233 | @@iterator(): Iterator<T>;
|
---|
| 234 | toSeq(): IndexedSeq<T>;
|
---|
| 235 | fromEntrySeq<K,V>(): KeyedSeq<K,V>;
|
---|
| 236 | interpose(separator: T): this;
|
---|
| 237 | interleave(...iterables: ESIterable<T>[]): this;
|
---|
| 238 | splice(
|
---|
| 239 | index: number,
|
---|
| 240 | removeNum: number,
|
---|
| 241 | ...values: T[]
|
---|
| 242 | ): this;
|
---|
| 243 |
|
---|
| 244 | zip<A>(
|
---|
| 245 | a: ESIterable<A>,
|
---|
| 246 | $?: null
|
---|
| 247 | ): IndexedIterable<[T,A]>;
|
---|
| 248 | zip<A,B>(
|
---|
| 249 | a: ESIterable<A>,
|
---|
| 250 | b: ESIterable<B>,
|
---|
| 251 | $?: null
|
---|
| 252 | ): IndexedIterable<[T,A,B]>;
|
---|
| 253 | zip<A,B,C>(
|
---|
| 254 | a: ESIterable<A>,
|
---|
| 255 | b: ESIterable<B>,
|
---|
| 256 | c: ESIterable<C>,
|
---|
| 257 | $?: null
|
---|
| 258 | ): IndexedIterable<[T,A,B,C]>;
|
---|
| 259 | zip<A,B,C,D>(
|
---|
| 260 | a: ESIterable<A>,
|
---|
| 261 | b: ESIterable<B>,
|
---|
| 262 | c: ESIterable<C>,
|
---|
| 263 | d: ESIterable<D>,
|
---|
| 264 | $?: null
|
---|
| 265 | ): IndexedIterable<[T,A,B,C,D]>;
|
---|
| 266 | zip<A,B,C,D,E>(
|
---|
| 267 | a: ESIterable<A>,
|
---|
| 268 | b: ESIterable<B>,
|
---|
| 269 | c: ESIterable<C>,
|
---|
| 270 | d: ESIterable<D>,
|
---|
| 271 | e: ESIterable<E>,
|
---|
| 272 | $?: null
|
---|
| 273 | ): IndexedIterable<[T,A,B,C,D,E]>;
|
---|
| 274 |
|
---|
| 275 | zipWith<A,R>(
|
---|
| 276 | zipper: (value: T, a: A) => R,
|
---|
| 277 | a: ESIterable<A>,
|
---|
| 278 | $?: null
|
---|
| 279 | ): IndexedIterable<R>;
|
---|
| 280 | zipWith<A,B,R>(
|
---|
| 281 | zipper: (value: T, a: A, b: B) => R,
|
---|
| 282 | a: ESIterable<A>,
|
---|
| 283 | b: ESIterable<B>,
|
---|
| 284 | $?: null
|
---|
| 285 | ): IndexedIterable<R>;
|
---|
| 286 | zipWith<A,B,C,R>(
|
---|
| 287 | zipper: (value: T, a: A, b: B, c: C) => R,
|
---|
| 288 | a: ESIterable<A>,
|
---|
| 289 | b: ESIterable<B>,
|
---|
| 290 | c: ESIterable<C>,
|
---|
| 291 | $?: null
|
---|
| 292 | ): IndexedIterable<R>;
|
---|
| 293 | zipWith<A,B,C,D,R>(
|
---|
| 294 | zipper: (value: T, a: A, b: B, c: C, d: D) => R,
|
---|
| 295 | a: ESIterable<A>,
|
---|
| 296 | b: ESIterable<B>,
|
---|
| 297 | c: ESIterable<C>,
|
---|
| 298 | d: ESIterable<D>,
|
---|
| 299 | $?: null
|
---|
| 300 | ): IndexedIterable<R>;
|
---|
| 301 | zipWith<A,B,C,D,E,R>(
|
---|
| 302 | zipper: (value: T, a: A, b: B, c: C, d: D, e: E) => R,
|
---|
| 303 | a: ESIterable<A>,
|
---|
| 304 | b: ESIterable<B>,
|
---|
| 305 | c: ESIterable<C>,
|
---|
| 306 | d: ESIterable<D>,
|
---|
| 307 | e: ESIterable<E>,
|
---|
| 308 | $?: null
|
---|
| 309 | ): IndexedIterable<R>;
|
---|
| 310 |
|
---|
| 311 | indexOf(searchValue: T): number;
|
---|
| 312 | lastIndexOf(searchValue: T): number;
|
---|
| 313 | findIndex(
|
---|
| 314 | predicate: (value: T, index: number, iter: this) => mixed,
|
---|
| 315 | context?: any
|
---|
| 316 | ): number;
|
---|
| 317 | findLastIndex(
|
---|
| 318 | predicate: (value: T, index: number, iter: this) => mixed,
|
---|
| 319 | context?: any
|
---|
| 320 | ): number;
|
---|
| 321 |
|
---|
| 322 | concat(...iters: ESIterable<T>[]): this;
|
---|
| 323 |
|
---|
| 324 | map<U>(
|
---|
| 325 | mapper: (value: T, index: number, iter: this) => U,
|
---|
| 326 | context?: any
|
---|
| 327 | ): /*this*/IndexedIterable<U>;
|
---|
| 328 |
|
---|
| 329 | flatMap<U>(
|
---|
| 330 | mapper: (value: T, index: number, iter: this) => ESIterable<U>,
|
---|
| 331 | context?: any
|
---|
| 332 | ): /*this*/IndexedIterable<U>;
|
---|
| 333 |
|
---|
| 334 | flatten(depth?: number): /*this*/IndexedIterable<any>;
|
---|
| 335 | flatten(shallow?: boolean): /*this*/IndexedIterable<any>;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | declare class SetIterable<T> extends Iterable<T,T> {
|
---|
| 339 | static <T>(iter?: ESIterable<T>): SetIterable<T>;
|
---|
| 340 |
|
---|
| 341 | @@iterator(): Iterator<T>;
|
---|
| 342 | toSeq(): SetSeq<T>;
|
---|
| 343 |
|
---|
| 344 | concat(...iters: ESIterable<T>[]): this;
|
---|
| 345 |
|
---|
| 346 | // `map` and `flatMap` cannot be defined further up the hiearchy, because the
|
---|
| 347 | // implementation for `KeyedIterable` allows the value type to change without
|
---|
| 348 | // constraining the key type. That does not work for `SetIterable` - the value
|
---|
| 349 | // and key types *must* match.
|
---|
| 350 | map<U>(
|
---|
| 351 | mapper: (value: T, value: T, iter: this) => U,
|
---|
| 352 | context?: any
|
---|
| 353 | ): /*this*/SetIterable<U>;
|
---|
| 354 |
|
---|
| 355 | flatMap<U>(
|
---|
| 356 | mapper: (value: T, value: T, iter: this) => ESIterable<U>,
|
---|
| 357 | context?: any
|
---|
| 358 | ): /*this*/SetIterable<U>;
|
---|
| 359 |
|
---|
| 360 | flatten(depth?: number): /*this*/SetIterable<any>;
|
---|
| 361 | flatten(shallow?: boolean): /*this*/SetIterable<any>;
|
---|
| 362 | }
|
---|
| 363 |
|
---|
| 364 | declare class Collection<K,V> extends _Iterable<K,V, typeof KeyedCollection, typeof IndexedCollection, typeof SetCollection> {
|
---|
| 365 | size: number;
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | declare class KeyedCollection<K,V> extends Collection<K,V> mixins KeyedIterable<K,V> {
|
---|
| 369 | toSeq(): KeyedSeq<K,V>;
|
---|
| 370 | }
|
---|
| 371 |
|
---|
| 372 | declare class IndexedCollection<T> extends Collection<number,T> mixins IndexedIterable<T> {
|
---|
| 373 | toSeq(): IndexedSeq<T>;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | declare class SetCollection<T> extends Collection<T,T> mixins SetIterable<T> {
|
---|
| 377 | toSeq(): SetSeq<T>;
|
---|
| 378 | }
|
---|
| 379 |
|
---|
| 380 | declare class Seq<K,V> extends _Iterable<K,V, typeof KeyedSeq, typeof IndexedSeq, typeof SetSeq> {
|
---|
| 381 | static <K,V>(iter: KeyedSeq<K,V>): KeyedSeq<K,V>;
|
---|
| 382 | static <T> (iter: SetSeq<T>): SetSeq<K,V>;
|
---|
| 383 | static <T> (iter?: ESIterable<T>): IndexedSeq<T>;
|
---|
| 384 | static <K,V>(iter: { [key: K]: V }): KeyedSeq<K,V>;
|
---|
| 385 |
|
---|
| 386 | static isSeq(maybeSeq: any): boolean;
|
---|
| 387 | static of<T>(...values: T[]): IndexedSeq<T>;
|
---|
| 388 |
|
---|
| 389 | size: ?number;
|
---|
| 390 | cacheResult(): this;
|
---|
| 391 | toSeq(): this;
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | declare class KeyedSeq<K,V> extends Seq<K,V> mixins KeyedIterable<K,V> {
|
---|
| 395 | static <K,V>(iter?: ESIterable<[K,V]>): KeyedSeq<K,V>;
|
---|
| 396 | static <K,V>(iter?: { [key: K]: V }): KeyedSeq<K,V>;
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | declare class IndexedSeq<T> extends Seq<number,T> mixins IndexedIterable<T> {
|
---|
| 400 | static <T>(iter?: ESIterable<T>): IndexedSeq<T>;
|
---|
| 401 | static of<T>(...values: T[]): IndexedSeq<T>;
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | declare class SetSeq<T> extends Seq<T,T> mixins SetIterable<T> {
|
---|
| 405 | static <T>(iter?: ESIterable<T>): IndexedSeq<T>;
|
---|
| 406 | static of<T>(...values: T[]): SetSeq<T>;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
| 409 | declare class List<T> extends IndexedCollection<T> {
|
---|
| 410 | static (iterable?: ESIterable<T>): List<T>;
|
---|
| 411 |
|
---|
| 412 | static isList(maybeList: any): boolean;
|
---|
| 413 | static of<T>(...values: T[]): List<T>;
|
---|
| 414 |
|
---|
| 415 | set<U>(index: number, value: U): List<T|U>;
|
---|
| 416 | delete(index: number): this;
|
---|
| 417 | remove(index: number): this;
|
---|
| 418 | insert<U>(index: number, value: U): List<T|U>;
|
---|
| 419 | clear(): this;
|
---|
| 420 | push<U>(...values: U[]): List<T|U>;
|
---|
| 421 | pop(): this;
|
---|
| 422 | unshift<U>(...values: U[]): List<T|U>;
|
---|
| 423 | shift(): this;
|
---|
| 424 |
|
---|
| 425 | update<U>(updater: (value: this) => List<U>): List<U>;
|
---|
| 426 | update<U>(index: number, updater: (value: T) => U): List<T|U>;
|
---|
| 427 | update<U>(index: number, notSetValue: U, updater: (value: T) => U): List<T|U>;
|
---|
| 428 |
|
---|
| 429 | merge<U>(...iterables: ESIterable<U>[]): List<T|U>;
|
---|
| 430 |
|
---|
| 431 | mergeWith<U,V>(
|
---|
| 432 | merger: (previous: T, next: U, key: number) => V,
|
---|
| 433 | ...iterables: ESIterable<U>[]
|
---|
| 434 | ): List<T|U|V>;
|
---|
| 435 |
|
---|
| 436 | mergeDeep<U>(...iterables: ESIterable<U>[]): List<T|U>;
|
---|
| 437 |
|
---|
| 438 | mergeDeepWith<U,V>(
|
---|
| 439 | merger: (previous: T, next: U, key: number) => V,
|
---|
| 440 | ...iterables: ESIterable<U>[]
|
---|
| 441 | ): List<T|U|V>;
|
---|
| 442 |
|
---|
| 443 | setSize(size: number): List<?T>;
|
---|
| 444 | setIn(keyPath: ESIterable<any>, value: any): List<T>;
|
---|
| 445 | deleteIn(keyPath: ESIterable<any>, value: any): this;
|
---|
| 446 | removeIn(keyPath: ESIterable<any>, value: any): this;
|
---|
| 447 |
|
---|
| 448 | updateIn(keyPath: ESIterable<any>, notSetValue: any, value: any): List<T>;
|
---|
| 449 | updateIn(keyPath: ESIterable<any>, value: any): List<T>;
|
---|
| 450 |
|
---|
| 451 | mergeIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): List<T>;
|
---|
| 452 | mergeDeepIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): List<T>;
|
---|
| 453 |
|
---|
| 454 | withMutations(mutator: (mutable: this) => any): this;
|
---|
| 455 | asMutable(): this;
|
---|
| 456 | asImmutable(): this;
|
---|
| 457 |
|
---|
| 458 | // Overrides that specialize return types
|
---|
| 459 | map<M>(
|
---|
| 460 | mapper: (value: T, index: number, iter: this) => M,
|
---|
| 461 | context?: any
|
---|
| 462 | ): List<M>;
|
---|
| 463 |
|
---|
| 464 | flatMap<M>(
|
---|
| 465 | mapper: (value: T, index: number, iter: this) => ESIterable<M>,
|
---|
| 466 | context?: any
|
---|
| 467 | ): List<M>;
|
---|
| 468 |
|
---|
| 469 | flatten(depth?: number): /*this*/List<any>;
|
---|
| 470 | flatten(shallow?: boolean): /*this*/List<any>;
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | declare class Map<K,V> extends KeyedCollection<K,V> {
|
---|
| 474 | static <K, V>(): Map<K, V>;
|
---|
| 475 | static <V>(obj?: {[key: string]: V}): Map<string, V>;
|
---|
| 476 | static <K, V>(iterable?: ESIterable<[K,V]>): Map<K, V>;
|
---|
| 477 |
|
---|
| 478 | static isMap(maybeMap: any): boolean;
|
---|
| 479 |
|
---|
| 480 | set<K_, V_>(key: K_, value: V_): Map<K|K_, V|V_>;
|
---|
| 481 | delete(key: K): this;
|
---|
| 482 | remove(key: K): this;
|
---|
| 483 | clear(): this;
|
---|
| 484 |
|
---|
| 485 | update<K_,V_>(updater: (value: this) => Map<K_,V_>): Map<K_,V_>;
|
---|
| 486 | update<V_>(key: K, updater: (value: V) => V_): Map<K,V|V_>;
|
---|
| 487 | update<V_>(key: K, notSetValue: V_, updater: (value: V) => V_): Map<K,V|V_>;
|
---|
| 488 |
|
---|
| 489 | merge<K_,V_>(
|
---|
| 490 | ...iterables: (ESIterable<[K_,V_]> | { [key: K_]: V_ })[]
|
---|
| 491 | ): Map<K|K_,V|V_>;
|
---|
| 492 |
|
---|
| 493 | mergeWith<K_,W,X>(
|
---|
| 494 | merger: (previous: V, next: W, key: number) => X,
|
---|
| 495 | ...iterables: ESIterable<W>[]
|
---|
| 496 | ): Map<K,V|W|X>;
|
---|
| 497 |
|
---|
| 498 | mergeDeep<K_,V_>(
|
---|
| 499 | ...iterables: (ESIterable<[K_,V_]> | { [key: K_]: V_ })[]
|
---|
| 500 | ): Map<K|K_,V|V_>;
|
---|
| 501 |
|
---|
| 502 | mergeDeepWith<K_,W,X>(
|
---|
| 503 | merger: (previous: V, next: W, key: number) => X,
|
---|
| 504 | ...iterables: ESIterable<W>[]
|
---|
| 505 | ): Map<K,V|W|X>;
|
---|
| 506 |
|
---|
| 507 | setIn(keyPath: ESIterable<any>, value: any): Map<K,V>;
|
---|
| 508 | deleteIn(keyPath: ESIterable<any>, value: any): this;
|
---|
| 509 | removeIn(keyPath: ESIterable<any>, value: any): this;
|
---|
| 510 |
|
---|
| 511 | updateIn(keyPath: ESIterable<any>, notSetValue: any, value: any): Map<K,V>;
|
---|
| 512 | updateIn(keyPath: ESIterable<any>, value: any): Map<K,V>;
|
---|
| 513 |
|
---|
| 514 | mergeIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): Map<K,V>;
|
---|
| 515 | mergeDeepIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): Map<K,V>;
|
---|
| 516 |
|
---|
| 517 | withMutations(mutator: (mutable: this) => any): this;
|
---|
| 518 | asMutable(): this;
|
---|
| 519 | asImmutable(): this;
|
---|
| 520 |
|
---|
| 521 | // Overrides that specialize return types
|
---|
| 522 |
|
---|
| 523 | map<V_>(
|
---|
| 524 | mapper: (value: V, key: K, iter: this) => V_,
|
---|
| 525 | context?: any
|
---|
| 526 | ): Map<K,V_>;
|
---|
| 527 |
|
---|
| 528 | flatMap<K_,V_>(
|
---|
| 529 | mapper: (value: V, key: K, iter: this) => ESIterable<[K_,V_]>,
|
---|
| 530 | context?: any
|
---|
| 531 | ): Map<K_,V_>;
|
---|
| 532 |
|
---|
| 533 | flip(): Map<V,K>;
|
---|
| 534 |
|
---|
| 535 | mapKeys<K_>(
|
---|
| 536 | mapper: (key: K, value: V, iter: this) => K_,
|
---|
| 537 | context?: any
|
---|
| 538 | ): Map<K_,V>;
|
---|
| 539 |
|
---|
| 540 | flatten(depth?: number): /*this*/Map<any,any>;
|
---|
| 541 | flatten(shallow?: boolean): /*this*/Map<any,any>;
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | // OrderedMaps have nothing that Maps do not have. We do not need to override constructor & other statics
|
---|
| 545 | declare class OrderedMap<K,V> extends Map<K,V> {
|
---|
| 546 | static isOrderedMap(maybeOrderedMap: any): bool;
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 | declare class Set<T> extends SetCollection<T> {
|
---|
| 550 | static <T>(iterable?: ESIterable<T>): Set<T>;
|
---|
| 551 |
|
---|
| 552 | static isSet(maybeSet: any): boolean;
|
---|
| 553 | static of<T>(...values: T[]): Set<T>;
|
---|
| 554 | static fromKeys<T>(iter: ESIterable<[T,any]>): Set<T>;
|
---|
| 555 | static fromKeys(iter: { [key: string]: any }): Set<string>;
|
---|
| 556 |
|
---|
| 557 | add<U>(value: U): Set<T|U>;
|
---|
| 558 | delete(value: T): this;
|
---|
| 559 | remove(value: T): this;
|
---|
| 560 | clear(): this;
|
---|
| 561 | union<U>(...iterables: ESIterable<U>[]): Set<T|U>;
|
---|
| 562 | merge<U>(...iterables: ESIterable<U>[]): Set<T|U>;
|
---|
| 563 | intersect<U>(...iterables: ESIterable<U>[]): Set<T&U>;
|
---|
| 564 | subtract<U>(...iterables: ESIterable<U>[]): Set<T>;
|
---|
| 565 |
|
---|
| 566 | withMutations(mutator: (mutable: this) => any): this;
|
---|
| 567 | asMutable(): this;
|
---|
| 568 | asImmutable(): this;
|
---|
| 569 |
|
---|
| 570 | // Overrides that specialize return types
|
---|
| 571 |
|
---|
| 572 | map<M>(
|
---|
| 573 | mapper: (value: T, value: T, iter: this) => M,
|
---|
| 574 | context?: any
|
---|
| 575 | ): Set<M>;
|
---|
| 576 |
|
---|
| 577 | flatMap<M>(
|
---|
| 578 | mapper: (value: T, value: T, iter: this) => ESIterable<M>,
|
---|
| 579 | context?: any
|
---|
| 580 | ): Set<M>;
|
---|
| 581 |
|
---|
| 582 | flatten(depth?: number): /*this*/Set<any>;
|
---|
| 583 | flatten(shallow?: boolean): /*this*/Set<any>;
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | // OrderedSets have nothing that Sets do not have. We do not need to override constructor & other statics
|
---|
| 587 | declare class OrderedSet<T> extends Set<T> {
|
---|
| 588 | static isOrderedSet(maybeOrderedSet: any): bool;
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | declare class Stack<T> extends IndexedCollection<T> {
|
---|
| 592 | static <T>(iterable?: ESIterable<T>): Stack<T>;
|
---|
| 593 |
|
---|
| 594 | static isStack(maybeStack: any): boolean;
|
---|
| 595 | static of<T>(...values: T[]): Stack<T>;
|
---|
| 596 |
|
---|
| 597 | peek(): T;
|
---|
| 598 | clear(): this;
|
---|
| 599 | unshift<U>(...values: U[]): Stack<T|U>;
|
---|
| 600 | unshiftAll<U>(iter: ESIterable<U>): Stack<T|U>;
|
---|
| 601 | shift(): this;
|
---|
| 602 | push<U>(...values: U[]): Stack<T|U>;
|
---|
| 603 | pushAll<U>(iter: ESIterable<U>): Stack<T|U>;
|
---|
| 604 | pop(): this;
|
---|
| 605 |
|
---|
| 606 | withMutations(mutator: (mutable: this) => any): this;
|
---|
| 607 | asMutable(): this;
|
---|
| 608 | asImmutable(): this;
|
---|
| 609 |
|
---|
| 610 | // Overrides that specialize return types
|
---|
| 611 |
|
---|
| 612 | map<U>(
|
---|
| 613 | mapper: (value: T, index: number, iter: this) => U,
|
---|
| 614 | context?: any
|
---|
| 615 | ): Stack<U>;
|
---|
| 616 |
|
---|
| 617 | flatMap<U>(
|
---|
| 618 | mapper: (value: T, index: number, iter: this) => ESIterable<U>,
|
---|
| 619 | context?: any
|
---|
| 620 | ): Stack<U>;
|
---|
| 621 |
|
---|
| 622 | flatten(depth?: number): /*this*/Stack<any>;
|
---|
| 623 | flatten(shallow?: boolean): /*this*/Stack<any>;
|
---|
| 624 | }
|
---|
| 625 |
|
---|
| 626 | declare function Range(start?: number, end?: number, step?: number): IndexedSeq<number>;
|
---|
| 627 | declare function Repeat<T>(value: T, times?: number): IndexedSeq<T>;
|
---|
| 628 |
|
---|
| 629 | //TODO: Once flow can extend normal Objects we can change this back to actually reflect Record behavior.
|
---|
| 630 | // For now fallback to any to not break existing Code
|
---|
| 631 | declare class Record<T: Object> {
|
---|
| 632 | static <T: Object>(spec: T, name?: string): /*T & Record<T>*/any;
|
---|
| 633 | get<A>(key: $Keys<T>): A;
|
---|
| 634 | set<A>(key: $Keys<T>, value: A): /*T & Record<T>*/this;
|
---|
| 635 | remove(key: $Keys<T>): /*T & Record<T>*/this;
|
---|
| 636 | }
|
---|
| 637 |
|
---|
| 638 | declare function fromJS(json: any, reviver?: (k: any, v: Iterable<any,any>) => any): any;
|
---|
| 639 | declare function is(first: any, second: any): boolean;
|
---|
| 640 |
|
---|
| 641 | export {
|
---|
| 642 | Iterable,
|
---|
| 643 | Collection,
|
---|
| 644 | Seq,
|
---|
| 645 |
|
---|
| 646 | // These classes do not actually exist under these names. But it is useful to
|
---|
| 647 | // have the types available.
|
---|
| 648 | KeyedIterable,
|
---|
| 649 | IndexedIterable,
|
---|
| 650 | SetIterable,
|
---|
| 651 | KeyedCollection,
|
---|
| 652 | IndexedCollection,
|
---|
| 653 | SetCollection,
|
---|
| 654 | KeyedSeq,
|
---|
| 655 | IndexedSeq,
|
---|
| 656 | SetSeq,
|
---|
| 657 |
|
---|
| 658 | List,
|
---|
| 659 | Map,
|
---|
| 660 | OrderedMap,
|
---|
| 661 | OrderedSet,
|
---|
| 662 | Range,
|
---|
| 663 | Repeat,
|
---|
| 664 | Record,
|
---|
| 665 | Set,
|
---|
| 666 | Stack,
|
---|
| 667 |
|
---|
| 668 | fromJS,
|
---|
| 669 | is,
|
---|
| 670 | }
|
---|