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 e54fb39542..25c2bcc65e 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([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,19 +73,19 @@ 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', () => { @@ -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,8 +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.get(c)).toEqual(c); + expect(symbolSet.contains(b)).toBe(true); }); it('operates on a large number of symbols, maintaining obj uniqueness', () => { @@ -276,8 +275,7 @@ describe('Set', () => { let symbolSet = Set(manySymbols); expect(symbolSet.size).toBe(12); - expect(symbolSet.has(manySymbols[10])).toBe(true); - expect(symbolSet.get(manySymbols[10])).toEqual(manySymbols[10]); + expect(symbolSet.contains(manySymbols[10])).toBe(true); }); }); diff --git a/dist/immutable-nonambient.d.ts b/dist/immutable-nonambient.d.ts index 21e57fb499..6a8079a920 100644 --- a/dist/immutable-nonambient.d.ts +++ b/dist/immutable-nonambient.d.ts @@ -2221,7 +2221,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; @@ -2690,10 +2690,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` @@ -3034,6 +3034,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. * @@ -3044,6 +3063,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. @@ -3965,6 +3995,25 @@ 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. @@ -4264,6 +4313,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 35c9ecd64b..0867f49fdd 100644 --- a/dist/immutable.d.ts +++ b/dist/immutable.d.ts @@ -2221,7 +2221,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; @@ -2690,10 +2690,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` @@ -3034,6 +3034,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. * @@ -3044,6 +3063,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. @@ -3965,6 +3995,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. @@ -4264,6 +4313,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 /** 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 e30da713d7..1b3165466c 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 4d12ff724c..d151e07405 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 35c9ecd64b..0867f49fdd 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -2221,7 +2221,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; @@ -2690,10 +2690,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` @@ -3034,6 +3034,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. * @@ -3044,6 +3063,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. @@ -3965,6 +3995,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. @@ -4264,6 +4313,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 /** 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);