Skip to content

Commit e2ee51d

Browse files
authored
Significant improvments to concat type definitions. (immutable-js#1153)
This adds significant improvements to the definitions for concat. Fixes immutable-js#1151
1 parent b3088ad commit e2ee51d

File tree

7 files changed

+282
-14
lines changed

7 files changed

+282
-14
lines changed

__tests__/List.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ describe('List', () => {
613613

614614
it('concat works like Array.prototype.concat', () => {
615615
let v1 = List.of(1, 2, 3);
616-
let v2 = v1.concat(4, List.of(5, 6), [7, 8], Seq({a: 9, b: 10}), Set.of(11, 12), null);
616+
let v2 = v1.concat(4, List([ 5, 6 ]), [7, 8], Seq([ 9, 10 ]), Set.of(11, 12), null);
617617
expect(v1.toArray()).toEqual([1, 2, 3]);
618618
expect(v2.toArray()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, null]);
619619
});

__tests__/concat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ describe('concat', () => {
5151
let a = Seq({a: 1, b: 2, c: 3});
5252
let b = [4, 5, 6];
5353
expect(() => {
54-
a.concat(b).toJS();
54+
a.concat(b as any).toJS();
5555
}).toThrow('Expected [K, V] tuple: 4');
5656
});
5757

dist/immutable-nonambient.d.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@
736736

737737
// Sequence algorithms
738738

739+
/**
740+
* Returns a new List with other values or collections concatenated to this one.
741+
*/
742+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): List<T | C>;
743+
739744
/**
740745
* Returns a new List with values passed through a
741746
* `mapper` function.
@@ -1308,6 +1313,12 @@
13081313

13091314
// Sequence algorithms
13101315

1316+
/**
1317+
* Returns a new Map with other collections concatenated to this one.
1318+
*/
1319+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Map<K | KC, V | VC>;
1320+
concat<C>(...collections: Array<{[key: string]: C}>): Map<K | string, V | C>;
1321+
13111322
/**
13121323
* Returns a new Map with values passed through a
13131324
* `mapper` function.
@@ -1394,6 +1405,12 @@
13941405

13951406
// Sequence algorithms
13961407

1408+
/**
1409+
* Returns a new OrderedMap with other collections concatenated to this one.
1410+
*/
1411+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): OrderedMap<K | KC, V | VC>;
1412+
concat<C>(...collections: Array<{[key: string]: C}>): OrderedMap<K | string, V | C>;
1413+
13971414
/**
13981415
* Returns a new OrderedMap with values passed through a
13991416
* `mapper` function.
@@ -1590,6 +1607,11 @@
15901607

15911608
// Sequence algorithms
15921609

1610+
/**
1611+
* Returns a new Set with other collections concatenated to this one.
1612+
*/
1613+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Set<T | C>;
1614+
15931615
/**
15941616
* Returns a new Set with values passed through a
15951617
* `mapper` function.
@@ -1659,6 +1681,11 @@
16591681

16601682
// Sequence algorithms
16611683

1684+
/**
1685+
* Returns a new OrderedSet with other collections concatenated to this one.
1686+
*/
1687+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): OrderedSet<T | C>;
1688+
16621689
/**
16631690
* Returns a new Set with values passed through a
16641691
* `mapper` function.
@@ -1852,6 +1879,11 @@
18521879

18531880
// Sequence algorithms
18541881

1882+
/**
1883+
* Returns a new Stack with other collections concatenated to this one.
1884+
*/
1885+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Stack<T | C>;
1886+
18551887
/**
18561888
* Returns a new Stack with values passed through a
18571889
* `mapper` function.
@@ -2205,6 +2237,15 @@
22052237
*/
22062238
toSeq(): this;
22072239

2240+
/**
2241+
* Returns a new Seq with other collections concatenated to this one.
2242+
*
2243+
* All entries will be present in the resulting Seq, even if they
2244+
* have the same key.
2245+
*/
2246+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Seq.Keyed<K | KC, V | VC>;
2247+
concat<C>(...collections: Array<{[key: string]: C}>): Seq.Keyed<K | string, V | C>;
2248+
22082249
/**
22092250
* Returns a new Seq.Keyed with values passed through a
22102251
* `mapper` function.
@@ -2286,6 +2327,11 @@
22862327
*/
22872328
toSeq(): this
22882329

2330+
/**
2331+
* Returns a new Seq with other collections concatenated to this one.
2332+
*/
2333+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Indexed<T | C>;
2334+
22892335
/**
22902336
* Returns a new Seq.Indexed with values passed through a
22912337
* `mapper` function.
@@ -2353,6 +2399,14 @@
23532399
*/
23542400
toSeq(): this
23552401

2402+
/**
2403+
* Returns a new Seq with other collections concatenated to this one.
2404+
*
2405+
* All entries will be present in the resulting Seq, even if they
2406+
* are duplicates.
2407+
*/
2408+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Set<T | C>;
2409+
23562410
/**
23572411
* Returns a new Seq.Set with values passed through a
23582412
* `mapper` function.
@@ -2565,6 +2619,12 @@
25652619
*/
25662620
flip(): this;
25672621

2622+
/**
2623+
* Returns a new Collection with other collections concatenated to this one.
2624+
*/
2625+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Collection.Keyed<K | KC, V | VC>;
2626+
concat<C>(...collections: Array<{[key: string]: C}>): Collection.Keyed<K | string, V | C>;
2627+
25682628
/**
25692629
* Returns a new Collection.Keyed with values passed through a
25702630
* `mapper` function.
@@ -2822,6 +2882,11 @@
28222882

28232883
// Sequence algorithms
28242884

2885+
/**
2886+
* Returns a new Collection with other collections concatenated to this one.
2887+
*/
2888+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Indexed<T | C>;
2889+
28252890
/**
28262891
* Returns a new Collection.Indexed with values passed through a
28272892
* `mapper` function.
@@ -2897,6 +2962,11 @@
28972962

28982963
// Sequence algorithms
28992964

2965+
/**
2966+
* Returns a new Collection with other collections concatenated to this one.
2967+
*/
2968+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Set<T | C>;
2969+
29002970
/**
29012971
* Returns a new Collection.Set with values passed through a
29022972
* `mapper` function.
@@ -3523,8 +3593,8 @@
35233593
* Returns a new Collection of the same type with other values and
35243594
* collection-like concatenated to this one.
35253595
*
3526-
* For Seqs, all entries will be present in
3527-
* the resulting collection, even if they have the same key.
3596+
* For Seqs, all entries will be present in the resulting Seq, even if they
3597+
* have the same key.
35283598
*/
35293599
concat(...valuesOrCollections: Array<any>): Collection<any, any>;
35303600

dist/immutable.d.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ declare module Immutable {
736736

737737
// Sequence algorithms
738738

739+
/**
740+
* Returns a new List with other values or collections concatenated to this one.
741+
*/
742+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): List<T | C>;
743+
739744
/**
740745
* Returns a new List with values passed through a
741746
* `mapper` function.
@@ -1308,6 +1313,12 @@ declare module Immutable {
13081313

13091314
// Sequence algorithms
13101315

1316+
/**
1317+
* Returns a new Map with other collections concatenated to this one.
1318+
*/
1319+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Map<K | KC, V | VC>;
1320+
concat<C>(...collections: Array<{[key: string]: C}>): Map<K | string, V | C>;
1321+
13111322
/**
13121323
* Returns a new Map with values passed through a
13131324
* `mapper` function.
@@ -1394,6 +1405,12 @@ declare module Immutable {
13941405

13951406
// Sequence algorithms
13961407

1408+
/**
1409+
* Returns a new OrderedMap with other collections concatenated to this one.
1410+
*/
1411+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): OrderedMap<K | KC, V | VC>;
1412+
concat<C>(...collections: Array<{[key: string]: C}>): OrderedMap<K | string, V | C>;
1413+
13971414
/**
13981415
* Returns a new OrderedMap with values passed through a
13991416
* `mapper` function.
@@ -1590,6 +1607,11 @@ declare module Immutable {
15901607

15911608
// Sequence algorithms
15921609

1610+
/**
1611+
* Returns a new Set with other collections concatenated to this one.
1612+
*/
1613+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Set<T | C>;
1614+
15931615
/**
15941616
* Returns a new Set with values passed through a
15951617
* `mapper` function.
@@ -1659,6 +1681,11 @@ declare module Immutable {
16591681

16601682
// Sequence algorithms
16611683

1684+
/**
1685+
* Returns a new OrderedSet with other collections concatenated to this one.
1686+
*/
1687+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): OrderedSet<T | C>;
1688+
16621689
/**
16631690
* Returns a new Set with values passed through a
16641691
* `mapper` function.
@@ -1852,6 +1879,11 @@ declare module Immutable {
18521879

18531880
// Sequence algorithms
18541881

1882+
/**
1883+
* Returns a new Stack with other collections concatenated to this one.
1884+
*/
1885+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Stack<T | C>;
1886+
18551887
/**
18561888
* Returns a new Stack with values passed through a
18571889
* `mapper` function.
@@ -2205,6 +2237,15 @@ declare module Immutable {
22052237
*/
22062238
toSeq(): this;
22072239

2240+
/**
2241+
* Returns a new Seq with other collections concatenated to this one.
2242+
*
2243+
* All entries will be present in the resulting Seq, even if they
2244+
* have the same key.
2245+
*/
2246+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Seq.Keyed<K | KC, V | VC>;
2247+
concat<C>(...collections: Array<{[key: string]: C}>): Seq.Keyed<K | string, V | C>;
2248+
22082249
/**
22092250
* Returns a new Seq.Keyed with values passed through a
22102251
* `mapper` function.
@@ -2286,6 +2327,11 @@ declare module Immutable {
22862327
*/
22872328
toSeq(): this
22882329

2330+
/**
2331+
* Returns a new Seq with other collections concatenated to this one.
2332+
*/
2333+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Indexed<T | C>;
2334+
22892335
/**
22902336
* Returns a new Seq.Indexed with values passed through a
22912337
* `mapper` function.
@@ -2353,6 +2399,14 @@ declare module Immutable {
23532399
*/
23542400
toSeq(): this
23552401

2402+
/**
2403+
* Returns a new Seq with other collections concatenated to this one.
2404+
*
2405+
* All entries will be present in the resulting Seq, even if they
2406+
* are duplicates.
2407+
*/
2408+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Set<T | C>;
2409+
23562410
/**
23572411
* Returns a new Seq.Set with values passed through a
23582412
* `mapper` function.
@@ -2565,6 +2619,12 @@ declare module Immutable {
25652619
*/
25662620
flip(): this;
25672621

2622+
/**
2623+
* Returns a new Collection with other collections concatenated to this one.
2624+
*/
2625+
concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Collection.Keyed<K | KC, V | VC>;
2626+
concat<C>(...collections: Array<{[key: string]: C}>): Collection.Keyed<K | string, V | C>;
2627+
25682628
/**
25692629
* Returns a new Collection.Keyed with values passed through a
25702630
* `mapper` function.
@@ -2822,6 +2882,11 @@ declare module Immutable {
28222882

28232883
// Sequence algorithms
28242884

2885+
/**
2886+
* Returns a new Collection with other collections concatenated to this one.
2887+
*/
2888+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Indexed<T | C>;
2889+
28252890
/**
28262891
* Returns a new Collection.Indexed with values passed through a
28272892
* `mapper` function.
@@ -2897,6 +2962,11 @@ declare module Immutable {
28972962

28982963
// Sequence algorithms
28992964

2965+
/**
2966+
* Returns a new Collection with other collections concatenated to this one.
2967+
*/
2968+
concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Set<T | C>;
2969+
29002970
/**
29012971
* Returns a new Collection.Set with values passed through a
29022972
* `mapper` function.
@@ -3523,8 +3593,8 @@ declare module Immutable {
35233593
* Returns a new Collection of the same type with other values and
35243594
* collection-like concatenated to this one.
35253595
*
3526-
* For Seqs, all entries will be present in
3527-
* the resulting collection, even if they have the same key.
3596+
* For Seqs, all entries will be present in the resulting Seq, even if they
3597+
* have the same key.
35283598
*/
35293599
concat(...valuesOrCollections: Array<any>): Collection<any, any>;
35303600

0 commit comments

Comments
 (0)