immutable 5.0.2 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/immutable.es.js +771 -476
- package/dist/immutable.js +5533 -5238
- package/dist/immutable.min.js +1 -1
- package/dist/{immutable.d.ts → type-definitions/immutable.d.ts} +253 -109
- package/dist/{immutable.js.flow → type-definitions/immutable.js.flow} +60 -60
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @ignore we should disable this rules, but let's activate it to enable eslint first */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
|
|
3
2
|
/**
|
|
4
3
|
* Immutable data encourages pure functions (data-in, data-out) and lends itself
|
|
5
4
|
* to much simpler application development and enabling techniques from
|
|
@@ -97,11 +96,12 @@ declare namespace Immutable {
|
|
|
97
96
|
type OnlyObject<T> = Extract<T, object>;
|
|
98
97
|
|
|
99
98
|
/** @ignore */
|
|
100
|
-
type ContainObject<T> =
|
|
101
|
-
|
|
102
|
-
?
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
type ContainObject<T> =
|
|
100
|
+
OnlyObject<T> extends object
|
|
101
|
+
? OnlyObject<T> extends never
|
|
102
|
+
? false
|
|
103
|
+
: true
|
|
104
|
+
: false;
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* @ignore
|
|
@@ -109,39 +109,46 @@ declare namespace Immutable {
|
|
|
109
109
|
* Used to convert deeply all immutable types to a plain TS type.
|
|
110
110
|
* Using `unknown` on object instead of recursive call as we have a circular reference issue
|
|
111
111
|
*/
|
|
112
|
-
export type DeepCopy<T> =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
112
|
+
export type DeepCopy<T> =
|
|
113
|
+
T extends Record<infer R>
|
|
114
|
+
? // convert Record to DeepCopy plain JS object
|
|
115
|
+
{
|
|
116
|
+
[key in keyof R]: ContainObject<R[key]> extends true
|
|
117
|
+
? unknown
|
|
118
|
+
: R[key];
|
|
119
|
+
}
|
|
120
|
+
: T extends MapOf<infer R>
|
|
121
|
+
? // convert MapOf to DeepCopy plain JS object
|
|
122
|
+
{
|
|
123
|
+
[key in keyof R]: ContainObject<R[key]> extends true
|
|
124
|
+
? unknown
|
|
125
|
+
: R[key];
|
|
126
|
+
}
|
|
127
|
+
: T extends Collection.Keyed<infer KeyedKey, infer V>
|
|
128
|
+
? // convert KeyedCollection to DeepCopy plain JS object
|
|
129
|
+
{
|
|
130
|
+
[key in KeyedKey extends PropertyKey
|
|
131
|
+
? KeyedKey
|
|
132
|
+
: string]: V extends object ? unknown : V;
|
|
133
|
+
}
|
|
134
|
+
: // convert IndexedCollection or Immutable.Set to DeepCopy plain JS array
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
136
|
+
T extends Collection<infer _, infer V>
|
|
137
|
+
? Array<DeepCopy<V>>
|
|
138
|
+
: T extends string | number // Iterable scalar types : should be kept as is
|
|
139
|
+
? T
|
|
140
|
+
: T extends Iterable<infer V> // Iterable are converted to plain JS array
|
|
141
|
+
? Array<DeepCopy<V>>
|
|
142
|
+
: T extends object // plain JS object are converted deeply
|
|
143
|
+
? {
|
|
144
|
+
[ObjectKey in keyof T]: ContainObject<
|
|
145
|
+
T[ObjectKey]
|
|
146
|
+
> extends true
|
|
147
|
+
? unknown
|
|
148
|
+
: T[ObjectKey];
|
|
149
|
+
}
|
|
150
|
+
: // other case : should be kept as is
|
|
151
|
+
T;
|
|
145
152
|
|
|
146
153
|
/**
|
|
147
154
|
* Describes which item in a pair should be placed first when sorting
|
|
@@ -164,6 +171,13 @@ declare namespace Immutable {
|
|
|
164
171
|
*/
|
|
165
172
|
export type Comparator<T> = (left: T, right: T) => PairSorting | number;
|
|
166
173
|
|
|
174
|
+
/**
|
|
175
|
+
* @ignore
|
|
176
|
+
*
|
|
177
|
+
* KeyPath allowed for `xxxIn` methods
|
|
178
|
+
*/
|
|
179
|
+
export type KeyPath<K> = OrderedCollection<K> | ArrayLike<K>;
|
|
180
|
+
|
|
167
181
|
/**
|
|
168
182
|
* Lists are ordered indexed dense collections, much like a JavaScript
|
|
169
183
|
* Array.
|
|
@@ -751,6 +765,14 @@ declare namespace Immutable {
|
|
|
751
765
|
zipper: (...values: Array<unknown>) => Z,
|
|
752
766
|
...collections: Array<Collection<unknown, unknown>>
|
|
753
767
|
): List<Z>;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Returns a new List with its values shuffled thanks to the
|
|
771
|
+
* [Fisher–Yates](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle)
|
|
772
|
+
* algorithm.
|
|
773
|
+
* It uses Math.random, but you can provide your own random number generator.
|
|
774
|
+
*/
|
|
775
|
+
shuffle(random?: () => number): this;
|
|
754
776
|
}
|
|
755
777
|
|
|
756
778
|
/**
|
|
@@ -831,9 +853,7 @@ declare namespace Immutable {
|
|
|
831
853
|
* not altered.
|
|
832
854
|
*/
|
|
833
855
|
function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
|
|
834
|
-
function Map<R extends { [key in
|
|
835
|
-
obj: R
|
|
836
|
-
): MapOf<R>;
|
|
856
|
+
function Map<R extends { [key in PropertyKey]: unknown }>(obj: R): MapOf<R>;
|
|
837
857
|
function Map<V>(obj: { [key: string]: V }): Map<string, V>;
|
|
838
858
|
function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;
|
|
839
859
|
|
|
@@ -842,7 +862,7 @@ declare namespace Immutable {
|
|
|
842
862
|
*
|
|
843
863
|
* @ignore
|
|
844
864
|
*/
|
|
845
|
-
interface MapOf<R extends { [key in
|
|
865
|
+
interface MapOf<R extends { [key in PropertyKey]: unknown }>
|
|
846
866
|
extends Map<keyof R, R[keyof R]> {
|
|
847
867
|
/**
|
|
848
868
|
* Returns the value associated with the provided key, or notSetValue if
|
|
@@ -853,12 +873,12 @@ declare namespace Immutable {
|
|
|
853
873
|
* that does not guarantee the key was not found.
|
|
854
874
|
*/
|
|
855
875
|
get<K extends keyof R>(key: K, notSetValue?: unknown): R[K];
|
|
856
|
-
get<NSV>(key:
|
|
876
|
+
get<NSV>(key: unknown, notSetValue: NSV): NSV;
|
|
857
877
|
|
|
858
878
|
// TODO `<const P extends ...>` can be used after dropping support for TypeScript 4.x
|
|
859
879
|
// reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters
|
|
860
880
|
// after this change, `as const` assertions can be remove from the type tests
|
|
861
|
-
getIn<P extends ReadonlyArray<
|
|
881
|
+
getIn<P extends ReadonlyArray<PropertyKey>>(
|
|
862
882
|
searchKeyPath: [...P],
|
|
863
883
|
notSetValue?: unknown
|
|
864
884
|
): RetrievePath<R, P>;
|
|
@@ -890,38 +910,48 @@ declare namespace Immutable {
|
|
|
890
910
|
// Loosely based off of this work.
|
|
891
911
|
// https://github.com/immutable-js/immutable-js/issues/1462#issuecomment-584123268
|
|
892
912
|
|
|
893
|
-
/**
|
|
894
|
-
|
|
913
|
+
/**
|
|
914
|
+
* @ignore
|
|
915
|
+
* Convert an immutable type to the equivalent plain TS type
|
|
916
|
+
* - MapOf -> object
|
|
917
|
+
* - List -> Array
|
|
918
|
+
*/
|
|
919
|
+
type GetNativeType<S> =
|
|
920
|
+
S extends MapOf<infer T> ? T : S extends List<infer I> ? Array<I> : S;
|
|
895
921
|
|
|
896
922
|
/** @ignore */
|
|
897
|
-
type Head<T extends ReadonlyArray<
|
|
923
|
+
type Head<T extends ReadonlyArray<unknown>> = T extends [
|
|
898
924
|
infer H,
|
|
899
|
-
...Array<unknown
|
|
925
|
+
...Array<unknown>,
|
|
900
926
|
]
|
|
901
927
|
? H
|
|
902
928
|
: never;
|
|
903
|
-
|
|
904
929
|
/** @ignore */
|
|
905
|
-
type Tail<T extends ReadonlyArray<
|
|
930
|
+
type Tail<T extends ReadonlyArray<unknown>> = T extends [unknown, ...infer I]
|
|
906
931
|
? I
|
|
907
932
|
: Array<never>;
|
|
908
|
-
|
|
909
933
|
/** @ignore */
|
|
910
934
|
type RetrievePathReducer<
|
|
911
935
|
T,
|
|
912
936
|
C,
|
|
913
|
-
L extends ReadonlyArray<
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
937
|
+
L extends ReadonlyArray<unknown>,
|
|
938
|
+
NT = GetNativeType<T>,
|
|
939
|
+
> =
|
|
940
|
+
// we can not retrieve a path from a primitive type
|
|
941
|
+
T extends string | number | boolean | null | undefined
|
|
942
|
+
? never
|
|
943
|
+
: C extends keyof NT
|
|
944
|
+
? L extends [] // L extends [] means we are at the end of the path, lets return the current type
|
|
945
|
+
? NT[C]
|
|
946
|
+
: // we are not at the end of the path, lets continue with the next key
|
|
947
|
+
RetrievePathReducer<NT[C], Head<L>, Tail<L>>
|
|
948
|
+
: // C is not a "key" of NT, so the path is invalid
|
|
949
|
+
never;
|
|
919
950
|
|
|
920
951
|
/** @ignore */
|
|
921
|
-
type RetrievePath<
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
> = P extends [] ? P : RetrievePathReducer<R, Head<P>, Tail<P>>;
|
|
952
|
+
type RetrievePath<R, P extends ReadonlyArray<PropertyKey>> = P extends []
|
|
953
|
+
? P
|
|
954
|
+
: RetrievePathReducer<R, Head<P>, Tail<P>>;
|
|
925
955
|
|
|
926
956
|
interface Map<K, V> extends Collection.Keyed<K, V> {
|
|
927
957
|
/**
|
|
@@ -1690,7 +1720,7 @@ declare namespace Immutable {
|
|
|
1690
1720
|
function OrderedMap<K, V>(collection?: Iterable<[K, V]>): OrderedMap<K, V>;
|
|
1691
1721
|
function OrderedMap<V>(obj: { [key: string]: V }): OrderedMap<string, V>;
|
|
1692
1722
|
|
|
1693
|
-
interface OrderedMap<K, V> extends Map<K, V> {
|
|
1723
|
+
interface OrderedMap<K, V> extends Map<K, V>, OrderedCollection<[K, V]> {
|
|
1694
1724
|
/**
|
|
1695
1725
|
* The number of entries in this OrderedMap.
|
|
1696
1726
|
*/
|
|
@@ -2175,7 +2205,7 @@ declare namespace Immutable {
|
|
|
2175
2205
|
collection?: Iterable<T> | ArrayLike<T>
|
|
2176
2206
|
): OrderedSet<T>;
|
|
2177
2207
|
|
|
2178
|
-
interface OrderedSet<T> extends Set<T> {
|
|
2208
|
+
interface OrderedSet<T> extends Set<T>, OrderedCollection<T> {
|
|
2179
2209
|
/**
|
|
2180
2210
|
* The number of items in this OrderedSet.
|
|
2181
2211
|
*/
|
|
@@ -2765,7 +2795,7 @@ declare namespace Immutable {
|
|
|
2765
2795
|
/**
|
|
2766
2796
|
* True if `maybeRecord` is an instance of a Record.
|
|
2767
2797
|
*/
|
|
2768
|
-
function isRecord(maybeRecord: unknown): maybeRecord is Record<
|
|
2798
|
+
function isRecord(maybeRecord: unknown): maybeRecord is Record<object>;
|
|
2769
2799
|
|
|
2770
2800
|
/**
|
|
2771
2801
|
* Records allow passing a second parameter to supply a descriptive name
|
|
@@ -2784,7 +2814,9 @@ declare namespace Immutable {
|
|
|
2784
2814
|
* Record.getDescriptiveName(me) // "Person"
|
|
2785
2815
|
* ```
|
|
2786
2816
|
*/
|
|
2787
|
-
function getDescriptiveName
|
|
2817
|
+
function getDescriptiveName<TProps extends object>(
|
|
2818
|
+
record: RecordOf<TProps>
|
|
2819
|
+
): string;
|
|
2788
2820
|
|
|
2789
2821
|
/**
|
|
2790
2822
|
* A Record.Factory is created by the `Record()` function. Record instances
|
|
@@ -2837,11 +2869,12 @@ declare namespace Immutable {
|
|
|
2837
2869
|
namespace Factory {}
|
|
2838
2870
|
|
|
2839
2871
|
interface Factory<TProps extends object> {
|
|
2840
|
-
(
|
|
2841
|
-
|
|
2872
|
+
(
|
|
2873
|
+
values?: Partial<TProps> | Iterable<[string, unknown]>
|
|
2874
|
+
): RecordOf<TProps>;
|
|
2842
2875
|
new (
|
|
2843
2876
|
values?: Partial<TProps> | Iterable<[string, unknown]>
|
|
2844
|
-
):
|
|
2877
|
+
): RecordOf<TProps>;
|
|
2845
2878
|
|
|
2846
2879
|
/**
|
|
2847
2880
|
* The name provided to `Record(values, name)` can be accessed with
|
|
@@ -2852,7 +2885,7 @@ declare namespace Immutable {
|
|
|
2852
2885
|
|
|
2853
2886
|
function Factory<TProps extends object>(
|
|
2854
2887
|
values?: Partial<TProps> | Iterable<[string, unknown]>
|
|
2855
|
-
):
|
|
2888
|
+
): RecordOf<TProps>;
|
|
2856
2889
|
}
|
|
2857
2890
|
|
|
2858
2891
|
/**
|
|
@@ -3120,14 +3153,14 @@ declare namespace Immutable {
|
|
|
3120
3153
|
*
|
|
3121
3154
|
* Converts keys to Strings.
|
|
3122
3155
|
*/
|
|
3123
|
-
toJS(): { [key in
|
|
3156
|
+
toJS(): { [key in PropertyKey]: DeepCopy<V> };
|
|
3124
3157
|
|
|
3125
3158
|
/**
|
|
3126
3159
|
* Shallowly converts this Keyed Seq to equivalent native JavaScript Object.
|
|
3127
3160
|
*
|
|
3128
3161
|
* Converts keys to Strings.
|
|
3129
3162
|
*/
|
|
3130
|
-
toJSON(): { [key in
|
|
3163
|
+
toJSON(): { [key in PropertyKey]: V };
|
|
3131
3164
|
|
|
3132
3165
|
/**
|
|
3133
3166
|
* Shallowly converts this collection to an Array.
|
|
@@ -3675,6 +3708,15 @@ declare namespace Immutable {
|
|
|
3675
3708
|
predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
|
3676
3709
|
context?: C
|
|
3677
3710
|
): [this, this];
|
|
3711
|
+
|
|
3712
|
+
/**
|
|
3713
|
+
* Returns a new Sequence of the same type with other values and
|
|
3714
|
+
* collection-like concatenated to this one.
|
|
3715
|
+
*
|
|
3716
|
+
* All entries will be present in the resulting Seq, even if they
|
|
3717
|
+
* have the same key.
|
|
3718
|
+
*/
|
|
3719
|
+
concat(...valuesOrCollections: Array<unknown>): Seq<unknown, unknown>;
|
|
3678
3720
|
}
|
|
3679
3721
|
|
|
3680
3722
|
/**
|
|
@@ -3719,14 +3761,14 @@ declare namespace Immutable {
|
|
|
3719
3761
|
*
|
|
3720
3762
|
* Converts keys to Strings.
|
|
3721
3763
|
*/
|
|
3722
|
-
toJS(): { [key in
|
|
3764
|
+
toJS(): { [key in PropertyKey]: DeepCopy<V> };
|
|
3723
3765
|
|
|
3724
3766
|
/**
|
|
3725
3767
|
* Shallowly converts this Keyed collection to equivalent native JavaScript Object.
|
|
3726
3768
|
*
|
|
3727
3769
|
* Converts keys to Strings.
|
|
3728
3770
|
*/
|
|
3729
|
-
toJSON(): { [key in
|
|
3771
|
+
toJSON(): { [key in PropertyKey]: V };
|
|
3730
3772
|
|
|
3731
3773
|
/**
|
|
3732
3774
|
* Shallowly converts this collection to an Array.
|
|
@@ -3897,7 +3939,7 @@ declare namespace Immutable {
|
|
|
3897
3939
|
collection?: Iterable<T> | ArrayLike<T>
|
|
3898
3940
|
): Collection.Indexed<T>;
|
|
3899
3941
|
|
|
3900
|
-
interface Indexed<T> extends Collection<number, T> {
|
|
3942
|
+
interface Indexed<T> extends Collection<number, T>, OrderedCollection<T> {
|
|
3901
3943
|
/**
|
|
3902
3944
|
* Deeply converts this Indexed collection to equivalent native JavaScript Array.
|
|
3903
3945
|
*/
|
|
@@ -4476,9 +4518,7 @@ declare namespace Immutable {
|
|
|
4476
4518
|
* `Collection.Indexed`, and `Collection.Set` become `Array`, while
|
|
4477
4519
|
* `Collection.Keyed` become `Object`, converting keys to Strings.
|
|
4478
4520
|
*/
|
|
4479
|
-
toJS():
|
|
4480
|
-
| Array<DeepCopy<V>>
|
|
4481
|
-
| { [key in string | number | symbol]: DeepCopy<V> };
|
|
4521
|
+
toJS(): Array<DeepCopy<V>> | { [key in PropertyKey]: DeepCopy<V> };
|
|
4482
4522
|
|
|
4483
4523
|
/**
|
|
4484
4524
|
* Shallowly converts this Collection to equivalent native JavaScript Array or Object.
|
|
@@ -4486,7 +4526,7 @@ declare namespace Immutable {
|
|
|
4486
4526
|
* `Collection.Indexed`, and `Collection.Set` become `Array`, while
|
|
4487
4527
|
* `Collection.Keyed` become `Object`, converting keys to Strings.
|
|
4488
4528
|
*/
|
|
4489
|
-
toJSON(): Array<V> | { [key in
|
|
4529
|
+
toJSON(): Array<V> | { [key in PropertyKey]: V };
|
|
4490
4530
|
|
|
4491
4531
|
/**
|
|
4492
4532
|
* Shallowly converts this collection to an Array.
|
|
@@ -5322,6 +5362,20 @@ declare namespace Immutable {
|
|
|
5322
5362
|
hashCode(): number;
|
|
5323
5363
|
}
|
|
5324
5364
|
|
|
5365
|
+
/**
|
|
5366
|
+
* Interface representing all oredered collections.
|
|
5367
|
+
* This includes `List`, `Stack`, `Map`, `OrderedMap`, `Set`, and `OrderedSet`.
|
|
5368
|
+
* return of `isOrdered()` return true in that case.
|
|
5369
|
+
*/
|
|
5370
|
+
interface OrderedCollection<T> {
|
|
5371
|
+
/**
|
|
5372
|
+
* Shallowly converts this collection to an Array.
|
|
5373
|
+
*/
|
|
5374
|
+
toArray(): Array<T>;
|
|
5375
|
+
|
|
5376
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
5377
|
+
}
|
|
5378
|
+
|
|
5325
5379
|
/**
|
|
5326
5380
|
* Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
|
|
5327
5381
|
*
|
|
@@ -5407,24 +5461,23 @@ declare namespace Immutable {
|
|
|
5407
5461
|
|
|
5408
5462
|
type FromJS<JSValue> = JSValue extends FromJSNoTransform
|
|
5409
5463
|
? JSValue
|
|
5410
|
-
: JSValue extends Array<
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5464
|
+
: JSValue extends Array<unknown>
|
|
5465
|
+
? FromJSArray<JSValue>
|
|
5466
|
+
: JSValue extends object
|
|
5467
|
+
? FromJSObject<JSValue>
|
|
5468
|
+
: unknown;
|
|
5415
5469
|
|
|
5416
5470
|
type FromJSNoTransform =
|
|
5417
|
-
| Collection<
|
|
5471
|
+
| Collection<unknown, unknown>
|
|
5418
5472
|
| number
|
|
5419
5473
|
| string
|
|
5420
5474
|
| null
|
|
5421
5475
|
| undefined;
|
|
5422
5476
|
|
|
5423
|
-
type FromJSArray<JSValue> =
|
|
5424
|
-
? List<FromJS<T>>
|
|
5425
|
-
: never;
|
|
5477
|
+
type FromJSArray<JSValue> =
|
|
5478
|
+
JSValue extends Array<infer T> ? List<FromJS<T>> : never;
|
|
5426
5479
|
|
|
5427
|
-
type FromJSObject<JSValue> = JSValue extends
|
|
5480
|
+
type FromJSObject<JSValue> = JSValue extends object
|
|
5428
5481
|
? Map<keyof JSValue, FromJS<JSValue[keyof JSValue]>>
|
|
5429
5482
|
: never;
|
|
5430
5483
|
|
|
@@ -5586,7 +5639,12 @@ declare namespace Immutable {
|
|
|
5586
5639
|
* isOrdered(Set()); // false
|
|
5587
5640
|
* ```
|
|
5588
5641
|
*/
|
|
5589
|
-
function isOrdered(
|
|
5642
|
+
function isOrdered<T>(
|
|
5643
|
+
maybeOrdered: Iterable<T>
|
|
5644
|
+
): maybeOrdered is OrderedCollection<T>;
|
|
5645
|
+
function isOrdered(
|
|
5646
|
+
maybeOrdered: unknown
|
|
5647
|
+
): maybeOrdered is OrderedCollection<unknown>;
|
|
5590
5648
|
|
|
5591
5649
|
/**
|
|
5592
5650
|
* True if `maybeValue` is a JavaScript Object which has *both* `equals()`
|
|
@@ -5648,7 +5706,7 @@ declare namespace Immutable {
|
|
|
5648
5706
|
/**
|
|
5649
5707
|
* True if `maybeRecord` is a Record.
|
|
5650
5708
|
*/
|
|
5651
|
-
function isRecord(maybeRecord: unknown): maybeRecord is Record<
|
|
5709
|
+
function isRecord(maybeRecord: unknown): maybeRecord is Record<object>;
|
|
5652
5710
|
|
|
5653
5711
|
/**
|
|
5654
5712
|
* Returns the value within the provided collection associated with the
|
|
@@ -5687,9 +5745,12 @@ declare namespace Immutable {
|
|
|
5687
5745
|
key: K,
|
|
5688
5746
|
notSetValue: unknown
|
|
5689
5747
|
): C[K];
|
|
5690
|
-
function get<V>(
|
|
5748
|
+
function get<V>(
|
|
5749
|
+
collection: { [key: PropertyKey]: V },
|
|
5750
|
+
key: string
|
|
5751
|
+
): V | undefined;
|
|
5691
5752
|
function get<V, NSV>(
|
|
5692
|
-
collection: { [key:
|
|
5753
|
+
collection: { [key: PropertyKey]: V },
|
|
5693
5754
|
key: string,
|
|
5694
5755
|
notSetValue: NSV
|
|
5695
5756
|
): V | NSV;
|
|
@@ -5737,7 +5798,7 @@ declare namespace Immutable {
|
|
|
5737
5798
|
function remove<
|
|
5738
5799
|
TProps extends object,
|
|
5739
5800
|
C extends Record<TProps>,
|
|
5740
|
-
K extends keyof TProps
|
|
5801
|
+
K extends keyof TProps,
|
|
5741
5802
|
>(collection: C, key: K): C;
|
|
5742
5803
|
function remove<C extends Array<unknown>>(collection: C, key: number): C;
|
|
5743
5804
|
function remove<C, K extends keyof C>(collection: C, key: K): C;
|
|
@@ -5773,7 +5834,7 @@ declare namespace Immutable {
|
|
|
5773
5834
|
function set<
|
|
5774
5835
|
TProps extends object,
|
|
5775
5836
|
C extends Record<TProps>,
|
|
5776
|
-
K extends keyof TProps
|
|
5837
|
+
K extends keyof TProps,
|
|
5777
5838
|
>(record: C, key: K, value: TProps[K]): C;
|
|
5778
5839
|
function set<V, C extends Array<V>>(collection: C, key: number, value: V): C;
|
|
5779
5840
|
function set<C, K extends keyof C>(object: C, key: K, value: C[K]): C;
|
|
@@ -5816,13 +5877,13 @@ declare namespace Immutable {
|
|
|
5816
5877
|
function update<
|
|
5817
5878
|
TProps extends object,
|
|
5818
5879
|
C extends Record<TProps>,
|
|
5819
|
-
K extends keyof TProps
|
|
5880
|
+
K extends keyof TProps,
|
|
5820
5881
|
>(record: C, key: K, updater: (value: TProps[K]) => TProps[K]): C;
|
|
5821
5882
|
function update<
|
|
5822
5883
|
TProps extends object,
|
|
5823
5884
|
C extends Record<TProps>,
|
|
5824
5885
|
K extends keyof TProps,
|
|
5825
|
-
NSV
|
|
5886
|
+
NSV,
|
|
5826
5887
|
>(
|
|
5827
5888
|
record: C,
|
|
5828
5889
|
key: K,
|
|
@@ -5863,6 +5924,9 @@ declare namespace Immutable {
|
|
|
5863
5924
|
updater: (value: V | NSV) => V
|
|
5864
5925
|
): { [key: string]: V };
|
|
5865
5926
|
|
|
5927
|
+
// TODO `<const P extends ...>` can be used after dropping support for TypeScript 4.x
|
|
5928
|
+
// reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters
|
|
5929
|
+
// after this change, `as const` assertions can be remove from the type tests
|
|
5866
5930
|
/**
|
|
5867
5931
|
* Returns the value at the provided key path starting at the provided
|
|
5868
5932
|
* collection, or notSetValue if the key path is not defined.
|
|
@@ -5877,10 +5941,20 @@ declare namespace Immutable {
|
|
|
5877
5941
|
* getIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p'], 'ifNotSet') // 'ifNotSet'
|
|
5878
5942
|
* ```
|
|
5879
5943
|
*/
|
|
5880
|
-
function getIn(
|
|
5881
|
-
|
|
5882
|
-
keyPath:
|
|
5883
|
-
|
|
5944
|
+
function getIn<C, P extends ReadonlyArray<PropertyKey>>(
|
|
5945
|
+
object: C,
|
|
5946
|
+
keyPath: [...P]
|
|
5947
|
+
): RetrievePath<C, P>;
|
|
5948
|
+
function getIn<C, P extends KeyPath<unknown>>(object: C, keyPath: P): unknown;
|
|
5949
|
+
function getIn<C, P extends ReadonlyArray<PropertyKey>, NSV>(
|
|
5950
|
+
collection: C,
|
|
5951
|
+
keyPath: [...P],
|
|
5952
|
+
notSetValue: NSV
|
|
5953
|
+
): RetrievePath<C, P> extends never ? NSV : RetrievePath<C, P>;
|
|
5954
|
+
function getIn<C, P extends KeyPath<unknown>, NSV>(
|
|
5955
|
+
object: C,
|
|
5956
|
+
keyPath: P,
|
|
5957
|
+
notSetValue: NSV
|
|
5884
5958
|
): unknown;
|
|
5885
5959
|
|
|
5886
5960
|
/**
|
|
@@ -5896,7 +5970,11 @@ declare namespace Immutable {
|
|
|
5896
5970
|
* hasIn({ x: { y: { z: 123 }}}, ['x', 'q', 'p']) // false
|
|
5897
5971
|
* ```
|
|
5898
5972
|
*/
|
|
5899
|
-
function hasIn(
|
|
5973
|
+
function hasIn(
|
|
5974
|
+
collection: string | boolean | number,
|
|
5975
|
+
keyPath: KeyPath<unknown>
|
|
5976
|
+
): never;
|
|
5977
|
+
function hasIn<K>(collection: unknown, keyPath: KeyPath<K>): boolean;
|
|
5900
5978
|
|
|
5901
5979
|
/**
|
|
5902
5980
|
* Returns a copy of the collection with the value at the key path removed.
|
|
@@ -5950,17 +6028,83 @@ declare namespace Immutable {
|
|
|
5950
6028
|
* console.log(original) // { x: { y: { z: 123 }}}
|
|
5951
6029
|
* ```
|
|
5952
6030
|
*/
|
|
5953
|
-
function updateIn<C
|
|
6031
|
+
function updateIn<K extends PropertyKey, V, C extends Collection<K, V>>(
|
|
5954
6032
|
collection: C,
|
|
5955
|
-
keyPath:
|
|
5956
|
-
updater: (
|
|
6033
|
+
keyPath: KeyPath<K>,
|
|
6034
|
+
updater: (
|
|
6035
|
+
value: RetrievePath<C, Array<K>> | undefined
|
|
6036
|
+
) => unknown | undefined
|
|
5957
6037
|
): C;
|
|
5958
|
-
function updateIn<C>(
|
|
6038
|
+
function updateIn<K extends PropertyKey, V, C extends Collection<K, V>, NSV>(
|
|
5959
6039
|
collection: C,
|
|
5960
|
-
keyPath:
|
|
5961
|
-
notSetValue:
|
|
5962
|
-
updater: (value:
|
|
6040
|
+
keyPath: KeyPath<K>,
|
|
6041
|
+
notSetValue: NSV,
|
|
6042
|
+
updater: (value: RetrievePath<C, Array<K>> | NSV) => unknown
|
|
6043
|
+
): C;
|
|
6044
|
+
function updateIn<
|
|
6045
|
+
TProps extends object,
|
|
6046
|
+
C extends Record<TProps>,
|
|
6047
|
+
K extends keyof TProps,
|
|
6048
|
+
>(
|
|
6049
|
+
record: C,
|
|
6050
|
+
keyPath: KeyPath<K>,
|
|
6051
|
+
updater: (value: RetrievePath<C, Array<K>>) => unknown
|
|
5963
6052
|
): C;
|
|
6053
|
+
function updateIn<
|
|
6054
|
+
TProps extends object,
|
|
6055
|
+
C extends Record<TProps>,
|
|
6056
|
+
K extends keyof TProps,
|
|
6057
|
+
NSV,
|
|
6058
|
+
>(
|
|
6059
|
+
record: C,
|
|
6060
|
+
keyPath: KeyPath<K>,
|
|
6061
|
+
notSetValue: NSV,
|
|
6062
|
+
updater: (value: RetrievePath<C, Array<K>> | NSV) => unknown
|
|
6063
|
+
): C;
|
|
6064
|
+
function updateIn<K extends PropertyKey, V, C extends Array<V>>(
|
|
6065
|
+
collection: Array<V>,
|
|
6066
|
+
keyPath: KeyPath<string | number>,
|
|
6067
|
+
updater: (
|
|
6068
|
+
value: RetrievePath<C, Array<K>> | undefined
|
|
6069
|
+
) => unknown | undefined
|
|
6070
|
+
): Array<V>;
|
|
6071
|
+
function updateIn<K extends PropertyKey, V, C extends Array<V>, NSV>(
|
|
6072
|
+
collection: Array<V>,
|
|
6073
|
+
keyPath: KeyPath<K>,
|
|
6074
|
+
notSetValue: NSV,
|
|
6075
|
+
updater: (value: RetrievePath<C, Array<K>> | NSV) => unknown
|
|
6076
|
+
): Array<V>;
|
|
6077
|
+
function updateIn<K extends PropertyKey, C>(
|
|
6078
|
+
object: C,
|
|
6079
|
+
keyPath: KeyPath<K>,
|
|
6080
|
+
updater: (value: RetrievePath<C, Array<K>>) => unknown
|
|
6081
|
+
): C;
|
|
6082
|
+
function updateIn<K extends PropertyKey, C, NSV>(
|
|
6083
|
+
object: C,
|
|
6084
|
+
keyPath: KeyPath<K>,
|
|
6085
|
+
notSetValue: NSV,
|
|
6086
|
+
updater: (value: RetrievePath<C, Array<K>> | NSV) => unknown
|
|
6087
|
+
): C;
|
|
6088
|
+
function updateIn<
|
|
6089
|
+
K extends PropertyKey,
|
|
6090
|
+
V,
|
|
6091
|
+
C extends { [key: PropertyKey]: V },
|
|
6092
|
+
>(
|
|
6093
|
+
collection: C,
|
|
6094
|
+
keyPath: KeyPath<K>,
|
|
6095
|
+
updater: (value: RetrievePath<C, Array<K>>) => unknown
|
|
6096
|
+
): { [key: PropertyKey]: V };
|
|
6097
|
+
function updateIn<
|
|
6098
|
+
K extends PropertyKey,
|
|
6099
|
+
V,
|
|
6100
|
+
C extends { [key: PropertyKey]: V },
|
|
6101
|
+
NSV,
|
|
6102
|
+
>(
|
|
6103
|
+
collection: C,
|
|
6104
|
+
keyPath: KeyPath<K>,
|
|
6105
|
+
notSetValue: NSV,
|
|
6106
|
+
updater: (value: RetrievePath<C, Array<K>> | NSV) => unknown
|
|
6107
|
+
): { [key: PropertyKey]: V };
|
|
5964
6108
|
|
|
5965
6109
|
/**
|
|
5966
6110
|
* Returns a copy of the collection with the remaining collections merged in.
|