From c750da48f2e335c3fc3082d6ac03eda61ece021b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 8 Aug 2017 16:25:55 -0700 Subject: [PATCH 01/14] Loosen type of Keyed.flatMap and descendants `Keyed.flatMap` says that `mapper` is allowed to change the key type and the value type, but `Collection.keyMap` says that `mapper` is only allowed to change the value type. This commit resolves the typing problem by making the return type's type arguments both `any`. It does not resolve the mismatch in the implementation of Map.flatMap, for example. --- type-definitions/Immutable.d.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index b58d1c768a..6cd8a0ea43 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1420,10 +1420,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -2502,10 +2502,10 @@ declare module Immutable { * * Similar to `seq.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Seq.Keyed; + ): Seq.Keyed; /** * Returns a new Seq with only the entries for which the `predicate` @@ -3004,10 +3004,10 @@ declare module Immutable { * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` From 60fc2760d0fadfb57e9b8dc1189a663c781e28e2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 09:32:15 -0700 Subject: [PATCH 02/14] Return Stack.flatMap's mapper's return type M should actually be Iterable since this is map, not flatMap. --- type-definitions/Immutable.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 6cd8a0ea43..1a2334e342 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -2054,7 +2054,7 @@ declare module Immutable { * Similar to `stack.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Stack; From e7d7ec98732b42c07e9cfa964e0f705e0ba732b2 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 09:35:16 -0700 Subject: [PATCH 03/14] Set types:K type parameter is now never The previous type, Set extends Collection, results in an incorrect type for `map` because `map` is not allowed to change the key type, only the value type. But map's previous return type of Set asserted that both the key *and* the value type changed. Now the key type is always `never`. --- type-definitions/Immutable.d.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 1a2334e342..e70e4ed533 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; From 9b0eb51cab03986d415d82d918b458363aa97485 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 09:51:27 -0700 Subject: [PATCH 04/14] Make OrderedSet's [flat]map/filter have key:never Missed in previous commit --- type-definitions/Immutable.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index e70e4ed533..5ab16b2be6 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; From 96b81eae9503d48fffcf4e86f290fdda325c0fac Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 09:56:49 -0700 Subject: [PATCH 05/14] Work around TS2.4:Collection.toSeq now returns any This works around the out-of-memory crash in Typescript 2.4 that arises from the compiler doing too much work when checking the correctness of `extends` relationships. The Typescript compiler got caught in a deep recursion when checking `toSeq: Seq`, the previous type. --- type-definitions/Immutable.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 5ab16b2be6..195e94b6db 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -3599,7 +3599,7 @@ declare module Immutable { * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): Seq; + toSeq(): any; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. From f9c94f9d45ca1426d9e124db7771d1097c667e90 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 10:53:34 -0700 Subject: [PATCH 06/14] Set extends Collection, not never Some immutable tooling doesn't understand never yet. --- type-definitions/Immutable.d.ts | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 195e94b6db..8649219b99 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: void, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: void, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: void, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: void, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: void, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: void, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: void, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: void, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: void, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: void, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: void, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: void, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: void, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: void, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: void, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: void, iter: this) => any, context?: any ): this; From adb9326e7903e53259bba0d150db736bbef9e254 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 10:59:14 -0700 Subject: [PATCH 07/14] Set extends Collection, not never Some immutable tooling doesn't understand void or never. --- type-definitions/Immutable.d.ts | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 8649219b99..977038809e 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: void, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: void, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: void, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: void, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: void, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: void, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: void, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: void, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: void, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: void, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: void, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: void, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: void, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: void, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: void, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: void, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; From af305ecf0d8a1ec0a6cb91a83a7bb8a2f3d49806 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 12:49:48 -0700 Subject: [PATCH 08/14] Tests:change Set.has->Set.contains Set.has shouldn't be used; it refers to the key type of the collection and the key type of Set is always number. Compare indexed types like List, where this is also true. --- __tests__/OrderedSet.ts | 10 +++---- __tests__/Set.ts | 62 ++++++++++++++++++++--------------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/__tests__/OrderedSet.ts b/__tests__/OrderedSet.ts index 5b8f014625..13ac487a54 100644 --- a/__tests__/OrderedSet.ts +++ b/__tests__/OrderedSet.ts @@ -6,9 +6,9 @@ describe('OrderedSet', () => { it('provides initial values in a mixed order', () => { let s = OrderedSet.of('C', 'B', 'A'); - expect(s.has('A')).toBe(true); - expect(s.has('B')).toBe(true); - expect(s.has('C')).toBe(true); + expect(s.contains('A')).toBe(true); + expect(s.contains('B')).toBe(true); + expect(s.contains('C')).toBe(true); expect(s.size).toBe(3); expect(s.toArray()).toEqual(['C', 'B', 'A']); }); @@ -35,8 +35,8 @@ describe('OrderedSet', () => { it('removes correctly', () => { let s = OrderedSet([ 'A', 'Z' ]).remove('A'); expect(s.size).toBe(1); - expect(s.has('A')).toBe(false); - expect(s.has('Z')).toBe(true); + expect(s.contains('A')).toBe(false); + expect(s.contains('Z')).toBe(true); }); it('respects order for equality', () => { diff --git a/__tests__/Set.ts b/__tests__/Set.ts index 1a9dbf77e5..2c91610dce 100644 --- a/__tests__/Set.ts +++ b/__tests__/Set.ts @@ -27,36 +27,36 @@ jasmine.addMatchers({ describe('Set', () => { it('accepts array of values', () => { let s = Set([1, 2, 3]); - expect(s.has(1)).toBe(true); - expect(s.has(2)).toBe(true); - expect(s.has(3)).toBe(true); - expect(s.has(4)).toBe(false); + expect(s.contains(1)).toBe(true); + expect(s.contains(2)).toBe(true); + expect(s.contains(3)).toBe(true); + expect(s.contains(4)).toBe(false); }); it('accepts array-like of values', () => { let s = Set({ length: 3, 1: 2 } as any); expect(s.size).toBe(2); - expect(s.has(undefined)).toBe(true); - expect(s.has(2)).toBe(true); - expect(s.has(1)).toBe(false); + expect(s.contains(undefined)).toBe(true); + expect(s.contains(2)).toBe(true); + expect(s.contains(1)).toBe(false); }); it('accepts string, an array-like collection', () => { let s = Set('abc'); expect(s.size).toBe(3); - expect(s.has('a')).toBe(true); - expect(s.has('b')).toBe(true); - expect(s.has('c')).toBe(true); - expect(s.has('abc')).toBe(false); + expect(s.contains('a')).toBe(true); + expect(s.contains('b')).toBe(true); + expect(s.contains('c')).toBe(true); + expect(s.contains('abc')).toBe(false); }); it('accepts sequence of values', () => { let seq = Seq.of(1, 2, 3); let s = Set(seq); - expect(s.has(1)).toBe(true); - expect(s.has(2)).toBe(true); - expect(s.has(3)).toBe(true); - expect(s.has(4)).toBe(false); + expect(s.contains(1)).toBe(true); + expect(s.contains(2)).toBe(true); + expect(s.contains(3)).toBe(true); + expect(s.contains(4)).toBe(false); }); it('accepts a keyed Seq as a set of entries', () => { @@ -73,27 +73,27 @@ describe('Set', () => { it('accepts object keys', () => { let s = Set.fromKeys({a: null, b: null, c: null}); - expect(s.has('a')).toBe(true); - expect(s.has('b')).toBe(true); - expect(s.has('c')).toBe(true); - expect(s.has('d')).toBe(false); + expect(s.contains('a')).toBe(true); + expect(s.contains('b')).toBe(true); + expect(s.contains('c')).toBe(true); + expect(s.contains('d')).toBe(false); }); it('accepts sequence keys', () => { let seq = Seq({a: null, b: null, c: null}); let s = Set.fromKeys(seq); - expect(s.has('a')).toBe(true); - expect(s.has('b')).toBe(true); - expect(s.has('c')).toBe(true); - expect(s.has('d')).toBe(false); + expect(s.contains('a')).toBe(true); + expect(s.contains('b')).toBe(true); + expect(s.contains('c')).toBe(true); + expect(s.contains('d')).toBe(false); }); it('accepts explicit values', () => { let s = Set.of(1, 2, 3); - expect(s.has(1)).toBe(true); - expect(s.has(2)).toBe(true); - expect(s.has(3)).toBe(true); - expect(s.has(4)).toBe(false); + expect(s.contains(1)).toBe(true); + expect(s.contains(2)).toBe(true); + expect(s.contains(3)).toBe(true); + expect(s.contains(4)).toBe(false); }); it('converts back to JS array', () => { @@ -193,8 +193,8 @@ describe('Set', () => { expect(s3.size).toBe(2); expect(s4.size).toBe(3); expect(s5.size).toBe(2); - expect(s3.has('b')).toBe(true); - expect(s5.has('b')).toBe(false); + expect(s3.contains('b')).toBe(true); + expect(s5.contains('b')).toBe(false); }); it('deletes down to empty set', () => { @@ -262,7 +262,7 @@ describe('Set', () => { let symbolSet = Set([ a, b, c, a, b, c, a, b, c, a, b, c ]); expect(symbolSet.size).toBe(3); - expect(symbolSet.has(b)).toBe(true); + expect(symbolSet.contains(b)).toBe(true); expect(symbolSet.get(c)).toEqual(c); }); @@ -276,7 +276,7 @@ describe('Set', () => { let symbolSet = Set(manySymbols); expect(symbolSet.size).toBe(12); - expect(symbolSet.has(manySymbols[10])).toBe(true); + expect(symbolSet.contains(manySymbols[10])).toBe(true); expect(symbolSet.get(manySymbols[10])).toEqual(manySymbols[10]); }); From ea7ffae139466d511fadfe1e8ac6961c4f1b1dca Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 12:52:26 -0700 Subject: [PATCH 09/14] Update .d.ts files in dist/ --- dist/immutable-nonambient.d.ts | 64 +++++++++++++++++----------------- dist/immutable.d.ts | 64 +++++++++++++++++----------------- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 45e80aad55..0d9e07703d 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -1420,10 +1420,10 @@ * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -1730,7 +1730,7 @@ * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; @@ -2054,7 +2054,7 @@ * Similar to `stack.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Stack; @@ -2502,10 +2502,10 @@ * * Similar to `seq.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Seq.Keyed; + ): Seq.Keyed; /** * Returns a new Seq with only the entries for which the `predicate` @@ -2670,7 +2670,7 @@ export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -3004,10 +3004,10 @@ * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` @@ -3294,7 +3294,7 @@ */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; @@ -3599,7 +3599,7 @@ * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): Seq; + toSeq(): any; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. diff --git a/dist/immutable.d.ts b/dist/immutable.d.ts index b58d1c768a..977038809e 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -1420,10 +1420,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; @@ -2054,7 +2054,7 @@ declare module Immutable { * Similar to `stack.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Stack; @@ -2502,10 +2502,10 @@ declare module Immutable { * * Similar to `seq.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Seq.Keyed; + ): Seq.Keyed; /** * Returns a new Seq with only the entries for which the `predicate` @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; } @@ -3004,10 +3004,10 @@ declare module Immutable { * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: T, iter: this) => M, + mapper: (value: T, key: number, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: T, iter: this) => Iterable, + mapper: (value: T, key: number, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: T, iter: this) => value is F, + predicate: (value: T, key: number, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: T, iter: this) => any, + predicate: (value: T, key: number, iter: this) => any, context?: any ): this; @@ -3599,7 +3599,7 @@ declare module Immutable { * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): Seq; + toSeq(): any; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. From b9ae2bdce74b73bd4dc2c89a26142c1db7c90b32 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 9 Aug 2017 13:09:57 -0700 Subject: [PATCH 10/14] Change Set key type back to never 1. Set once again extends Collection. 2. pages/lib/TypeKind.js understands Never now. 3. Remove calls to Set.has and Set.get. These refer to the key type, which is now `never`. Set.contains should be used instead of Set.has. `if (Set.contains(x)) Set.get(x)` should be replaced with `if (Set.contains(x)) x` since Sets shouldn't change the identity of their items. --- __tests__/Set.ts | 2 -- dist/immutable-nonambient.d.ts | 36 ++++++++++++++++----------------- dist/immutable.d.ts | 36 ++++++++++++++++----------------- pages/lib/TypeKind.js | 19 ++++++++--------- pages/lib/genTypeDefData.js | 4 ++++ pages/src/docs/src/Defs.js | 4 ++++ type-definitions/Immutable.d.ts | 36 ++++++++++++++++----------------- 7 files changed, 72 insertions(+), 65 deletions(-) diff --git a/__tests__/Set.ts b/__tests__/Set.ts index 2c91610dce..1449d56fe0 100644 --- a/__tests__/Set.ts +++ b/__tests__/Set.ts @@ -263,7 +263,6 @@ describe('Set', () => { let symbolSet = Set([ a, b, c, a, b, c, a, b, c, a, b, c ]); expect(symbolSet.size).toBe(3); expect(symbolSet.contains(b)).toBe(true); - expect(symbolSet.get(c)).toEqual(c); }); it('operates on a large number of symbols, maintaining obj uniqueness', () => { @@ -277,7 +276,6 @@ describe('Set', () => { let symbolSet = Set(manySymbols); expect(symbolSet.size).toBe(12); expect(symbolSet.contains(manySymbols[10])).toBe(true); - expect(symbolSet.get(manySymbols[10])).toEqual(manySymbols[10]); }); }); diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 0d9e07703d..0329cee05e 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -1730,7 +1730,7 @@ * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; diff --git a/dist/immutable.d.ts b/dist/immutable.d.ts index 977038809e..195e94b6db 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; diff --git a/pages/lib/TypeKind.js b/pages/lib/TypeKind.js index b9f7256130..a4af4b09ff 100644 --- a/pages/lib/TypeKind.js +++ b/pages/lib/TypeKind.js @@ -6,17 +6,18 @@ var TypeKind = { String: 3, Object: 4, Array: 5, - Function: 6, + Never: 6, + Function: 7, - Param: 7, - Type: 8, + Param: 8, + Type: 9, - This: 9, - Undefined: 10, - Union: 11, - Tuple: 12, - Indexed: 13, - Operator: 14 + This: 10, + Undefined: 11, + Union: 12, + Tuple: 13, + Indexed: 14, + Operator: 15 }; module.exports = TypeKind; diff --git a/pages/lib/genTypeDefData.js b/pages/lib/genTypeDefData.js index b28565102e..694ac6bfea 100644 --- a/pages/lib/genTypeDefData.js +++ b/pages/lib/genTypeDefData.js @@ -262,6 +262,10 @@ function DocVisitor(source) { function parseType(node) { switch (node.kind) { + case ts.SyntaxKind.NeverKeyword: + return { + k: TypeKind.NeverKeyword + }; case ts.SyntaxKind.AnyKeyword: return { k: TypeKind.Any diff --git a/pages/src/docs/src/Defs.js b/pages/src/docs/src/Defs.js index 09ff6c9e31..2c7a5a634c 100644 --- a/pages/src/docs/src/Defs.js +++ b/pages/src/docs/src/Defs.js @@ -80,6 +80,8 @@ var TypeDef = React.createClass({ var type = this.props.type; var prefix = this.props.prefix; switch (type.k) { + case TypeKind.Never: + return this.wrap('primitive', 'never'); case TypeKind.Any: return this.wrap('primitive', 'any'); case TypeKind.This: @@ -295,6 +297,8 @@ function typeLength(info, type) { throw new Error('Expected type'); } switch (type.k) { + case TypeKind.Never: + return 5; case TypeKind.Any: return 3; case TypeKind.This: diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 977038809e..195e94b6db 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; } @@ -3294,7 +3294,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3331,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: number, iter: this) => M, + mapper: (value: T, key: never, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3341,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: number, iter: this) => Iterable, + mapper: (value: T, key: never, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3353,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: number, iter: this) => value is F, + predicate: (value: T, key: never, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: number, iter: this) => any, + predicate: (value: T, key: never, iter: this) => any, context?: any ): this; From 482d4195e75f9a93a3ad4f51504ababf68868ad8 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 5 Sep 2017 11:19:45 -0700 Subject: [PATCH 11/14] Return Collection.toSeq's origin type: Seq Previously it was any to work around Typescript 2.4's out-of-memory crash. --- dist/immutable-nonambient.d.ts | 2 +- dist/immutable.d.ts | 2 +- type-definitions/Immutable.d.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 0329cee05e..1b73563dbd 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -3599,7 +3599,7 @@ * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): any; + toSeq(): Seq; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. diff --git a/dist/immutable.d.ts b/dist/immutable.d.ts index 195e94b6db..5ab16b2be6 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -3599,7 +3599,7 @@ declare module Immutable { * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): any; + toSeq(): Seq; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 195e94b6db..5ab16b2be6 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -3599,7 +3599,7 @@ declare module Immutable { * Converts this Collection to a Seq of the same kind (indexed, * keyed, or set). */ - toSeq(): any; + toSeq(): Seq; /** * Returns a Seq.Keyed from this Collection where indices are treated as keys. From 2e7576e82f0b7b15541fa668650c7930f4bb3668 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Sep 2017 13:39:37 -0700 Subject: [PATCH 12/14] Overloads allow inconsistent Collection subclasses --- type-definitions/Immutable.d.ts | 114 ++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 27 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index 5ab16b2be6..860caecc26 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -1420,10 +1420,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -2820,6 +2820,25 @@ declare module Immutable { context?: any ): Seq; + /** + * Returns a new Seq with values passed through a + * `mapper` function. + * + * ```js + * const { Seq } = require('immutable') + * Seq([ 1, 2 ]).map(x => 10 * x) + * // Seq [ 10, 20 ] + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets. + */ + map( + mapper: (value: V, key: K, iter: this) => M, + context?: any + ): Seq; + /** * Flat-maps the Seq, returning a Seq of the same type. * @@ -2830,6 +2849,17 @@ declare module Immutable { context?: any ): Seq; + /** + * Flat-maps the Seq, returning a Seq of the same type. + * + * Similar to `seq.map(...).flatten(true)`. + * Note: Used only for sets. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, + context?: any + ): Seq; + /** * Returns a new Seq with only the values for which the `predicate` * function returns true. @@ -3004,10 +3034,10 @@ declare module Immutable { * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` @@ -3294,7 +3324,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3361,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3371,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3383,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -3704,6 +3734,25 @@ declare module Immutable { context?: any ): Collection; + /** + * Returns a new Collection of the same type with values passed through a + * `mapper` function. + * + * ```js + * const { Collection } = require('immutable') + * Collection({ a: 1, b: 2 }).map(x => 10 * x) + * // Seq { "a": 10, "b": 20 } + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets, which return Collection but are otherwise + * identical to normal `map()`. + */ + map( + ...args: never[] + ): any; + /** * Returns a new Collection of the same type with only the entries for which * the `predicate` function returns true. @@ -3997,6 +4046,17 @@ declare module Immutable { context?: any ): Collection; + /** + * Flat-maps the Collection, returning a Collection of the same type. + * + * Similar to `collection.map(...).flatten(true)`. + * Used for Dictionaries only. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + context?: any + ): Collection; + // Reducing a value /** From f393a68ea4a48be9f234c650e152d108158daffa Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Sep 2017 13:40:54 -0700 Subject: [PATCH 13/14] Update dist files --- dist/immutable-nonambient.d.ts | 113 +++++++++++++++++++++++++-------- dist/immutable.d.ts | 113 +++++++++++++++++++++++++-------- 2 files changed, 172 insertions(+), 54 deletions(-) diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 1b73563dbd..ae1606e6cd 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -1420,10 +1420,10 @@ * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -1730,7 +1730,7 @@ * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -2820,6 +2820,25 @@ context?: any ): Seq; + /** + * Returns a new Seq with values passed through a + * `mapper` function. + * + * ```js + * const { Seq } = require('immutable') + * Seq([ 1, 2 ]).map(x => 10 * x) + * // Seq [ 10, 20 ] + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets. + */ + map( + mapper: (value: V, key: K, iter: this) => M, + context?: any + ): Seq; + /** * Flat-maps the Seq, returning a Seq of the same type. * @@ -2830,6 +2849,17 @@ context?: any ): Seq; + /** + * Flat-maps the Seq, returning a Seq of the same type. + * + * Similar to `seq.map(...).flatten(true)`. + * Note: Used only for sets. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, + context?: any + ): Seq; + /** * Returns a new Seq with only the values for which the `predicate` * function returns true. @@ -3004,10 +3034,10 @@ * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` @@ -3294,7 +3324,7 @@ */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3361,7 @@ * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3371,7 @@ * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3383,11 @@ * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -3704,6 +3734,24 @@ context?: any ): Collection; + /** + * Returns a new Collection of the same type with values passed through a + * `mapper` function. + * + * ```js + * const { Collection } = require('immutable') + * Collection({ a: 1, b: 2 }).map(x => 10 * x) + * // Seq { "a": 10, "b": 20 } + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets. + */ + map( + ...args: never[] + ): any; + /** * Returns a new Collection of the same type with only the entries for which * the `predicate` function returns true. @@ -3997,6 +4045,17 @@ context?: any ): Collection; + /** + * Flat-maps the Collection, returning a Collection of the same type. + * + * Similar to `collection.map(...).flatten(true)`. + * Used for Dictionaries only. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + context?: any + ): Collection; + // Reducing a value /** diff --git a/dist/immutable.d.ts b/dist/immutable.d.ts index 5ab16b2be6..048e1f8eef 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -1420,10 +1420,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Map; + ): Map; /** * Returns a new Map with only the entries for which the `predicate` @@ -1533,10 +1533,10 @@ declare module Immutable { * * Similar to `data.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): OrderedMap; + ): OrderedMap; /** * Returns a new OrderedMap with only the entries for which the `predicate` @@ -1730,7 +1730,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Set; @@ -1740,7 +1740,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Set; @@ -1752,11 +1752,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -1825,7 +1825,7 @@ declare module Immutable { * value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): OrderedSet; @@ -1835,7 +1835,7 @@ declare module Immutable { * Similar to `set.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): OrderedSet; @@ -1847,11 +1847,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): OrderedSet; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -2670,7 +2670,7 @@ declare module Immutable { export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; - export interface Set extends Seq, Collection.Set { + export interface Set extends Seq, Collection.Set { /** * Deeply converts this Set Seq to equivalent native JavaScript Array. */ @@ -2707,7 +2707,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Seq.Set; @@ -2717,7 +2717,7 @@ declare module Immutable { * Similar to `seq.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Seq.Set; @@ -2729,11 +2729,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Seq.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; } @@ -2820,6 +2820,25 @@ declare module Immutable { context?: any ): Seq; + /** + * Returns a new Seq with values passed through a + * `mapper` function. + * + * ```js + * const { Seq } = require('immutable') + * Seq([ 1, 2 ]).map(x => 10 * x) + * // Seq [ 10, 20 ] + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets. + */ + map( + mapper: (value: V, key: K, iter: this) => M, + context?: any + ): Seq; + /** * Flat-maps the Seq, returning a Seq of the same type. * @@ -2830,6 +2849,17 @@ declare module Immutable { context?: any ): Seq; + /** + * Flat-maps the Seq, returning a Seq of the same type. + * + * Similar to `seq.map(...).flatten(true)`. + * Note: Used only for sets. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable, + context?: any + ): Seq; + /** * Returns a new Seq with only the values for which the `predicate` * function returns true. @@ -3004,10 +3034,10 @@ declare module Immutable { * * Similar to `collection.map(...).flatten(true)`. */ - flatMap( - mapper: (value: V, key: K, iter: this) => Iterable, + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, context?: any - ): Collection.Keyed; + ): Collection.Keyed; /** * Returns a new Collection with only the values for which the `predicate` @@ -3294,7 +3324,7 @@ declare module Immutable { */ export function Set(collection: Iterable): Collection.Set; - export interface Set extends Collection { + export interface Set extends Collection { /** * Deeply converts this Set collection to equivalent native JavaScript Array. */ @@ -3331,7 +3361,7 @@ declare module Immutable { * same value at every step. */ map( - mapper: (value: T, key: never, iter: this) => M, + mapper: (value: T, key: T, iter: this) => M, context?: any ): Collection.Set; @@ -3341,7 +3371,7 @@ declare module Immutable { * Similar to `collection.map(...).flatten(true)`. */ flatMap( - mapper: (value: T, key: never, iter: this) => Iterable, + mapper: (value: T, key: T, iter: this) => Iterable, context?: any ): Collection.Set; @@ -3353,11 +3383,11 @@ declare module Immutable { * not filtering out any values. */ filter( - predicate: (value: T, key: never, iter: this) => value is F, + predicate: (value: T, key: T, iter: this) => value is F, context?: any ): Collection.Set; filter( - predicate: (value: T, key: never, iter: this) => any, + predicate: (value: T, key: T, iter: this) => any, context?: any ): this; @@ -3704,6 +3734,24 @@ declare module Immutable { context?: any ): Collection; + /** + * Returns a new Collection of the same type with values passed through a + * `mapper` function. + * + * ```js + * const { Collection } = require('immutable') + * Collection({ a: 1, b: 2 }).map(x => 10 * x) + * // Seq { "a": 10, "b": 20 } + * ``` + * + * Note: `map()` always returns a new instance, even if it produced the same + * value at every step. + * Note: used only for sets. + */ + map( + ...args: never[] + ): any; + /** * Returns a new Collection of the same type with only the entries for which * the `predicate` function returns true. @@ -3997,6 +4045,17 @@ declare module Immutable { context?: any ): Collection; + /** + * Flat-maps the Collection, returning a Collection of the same type. + * + * Similar to `collection.map(...).flatten(true)`. + * Used for Dictionaries only. + */ + flatMap( + mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>, + context?: any + ): Collection; + // Reducing a value /** From 041cc87426e1acee76d0634c3d3881c14369e3e9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 29 Sep 2017 13:50:09 -0700 Subject: [PATCH 14/14] Update dist and ts-tests --- dist/immutable-nonambient.d.ts | 3 ++- dist/immutable.d.ts | 3 ++- type-definitions/ts-tests/ordered-set.ts | 2 +- type-definitions/ts-tests/set.ts | 2 +- type-definitions/ts-tests/stack.ts | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 9ce001b75d..6a8079a920 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -4007,7 +4007,8 @@ * * Note: `map()` always returns a new instance, even if it produced the same * value at every step. - * Note: used only for sets. + * Note: used only for sets, which return Collection but are otherwise + * identical to normal `map()`. */ map( ...args: never[] diff --git a/dist/immutable.d.ts b/dist/immutable.d.ts index d46fe0397e..0867f49fdd 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -4007,7 +4007,8 @@ declare module Immutable { * * Note: `map()` always returns a new instance, even if it produced the same * value at every step. - * Note: used only for sets. + * Note: used only for sets, which return Collection but are otherwise + * identical to normal `map()`. */ map( ...args: never[] diff --git a/type-definitions/ts-tests/ordered-set.ts b/type-definitions/ts-tests/ordered-set.ts index ba57633248..6f43d93c37 100644 --- a/type-definitions/ts-tests/ordered-set.ts +++ b/type-definitions/ts-tests/ordered-set.ts @@ -35,7 +35,7 @@ import { OrderedSet, Map } from '../../'; { // .fromKeys - // $ExpectType OrderedSet + // $ExpectType OrderedSet OrderedSet.fromKeys(Map()); // $ExpectType OrderedSet diff --git a/type-definitions/ts-tests/set.ts b/type-definitions/ts-tests/set.ts index de675e8a63..5faf843725 100644 --- a/type-definitions/ts-tests/set.ts +++ b/type-definitions/ts-tests/set.ts @@ -35,7 +35,7 @@ import { Set, Map } from '../../'; { // .fromKeys - // $ExpectType Set + // $ExpectType Set Set.fromKeys(Map()); // $ExpectType Set diff --git a/type-definitions/ts-tests/stack.ts b/type-definitions/ts-tests/stack.ts index b4e1a05f07..f38a3d5fbd 100644 --- a/type-definitions/ts-tests/stack.ts +++ b/type-definitions/ts-tests/stack.ts @@ -156,13 +156,13 @@ import { Stack } from '../../'; { // #flatMap // $ExpectType Stack - Stack().flatMap((value: number, key: number, iter: Stack) => 1); + Stack().flatMap((value: number, key: number, iter: Stack) => [1]); // $ExpectType Stack Stack().flatMap((value: number, key: number, iter: Stack) => 'a'); // $ExpectType Stack - Stack().flatMap((value: number, key: number, iter: Stack) => 1); + Stack().flatMap((value: number, key: number, iter: Stack) => [1]); // $ExpectError Stack().flatMap((value: number, key: number, iter: Stack) => 1);