Skip to content

Fix typescript types for typescript 2.4 #1285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions __tests__/OrderedSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
});
Expand All @@ -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', () => {
Expand Down
56 changes: 27 additions & 29 deletions __tests__/Set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>({ 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', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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);
});

});
Expand Down
68 changes: 64 additions & 4 deletions dist/immutable-nonambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@
* Similar to `stack.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => M,
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: any
): Stack<M>;

Expand Down Expand Up @@ -2690,10 +2690,10 @@
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: any
): Seq.Keyed<KM, VM>;
): Seq.Keyed<any, any>;

/**
* Returns a new Seq with only the entries for which the `predicate`
Expand Down Expand Up @@ -3034,6 +3034,25 @@
context?: any
): Seq<K, M>;

/**
* 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<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: any
): Seq<M, M>;

/**
* Flat-maps the Seq, returning a Seq of the same type.
*
Expand All @@ -3044,6 +3063,17 @@
context?: any
): Seq<K, M>;

/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
* Note: Used only for sets.
*/
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: any
): Seq<M, M>;

/**
* Returns a new Seq with only the values for which the `predicate`
* function returns true.
Expand Down Expand Up @@ -3965,6 +3995,25 @@
context?: any
): Collection<K, M>;

/**
* 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<M, M> but are otherwise
* identical to normal `map()`.
*/
map<M>(
...args: never[]
): any;

/**
* Returns a new Collection of the same type with only the entries for which
* the `predicate` function returns true.
Expand Down Expand Up @@ -4264,6 +4313,17 @@
context?: any
): Collection<K, M>;

/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
* Used for Dictionaries only.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: any
): Collection<KM, VM>;

// Reducing a value

/**
Expand Down
68 changes: 64 additions & 4 deletions dist/immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2221,7 +2221,7 @@ declare module Immutable {
* Similar to `stack.map(...).flatten(true)`.
*/
flatMap<M>(
mapper: (value: T, key: number, iter: this) => M,
mapper: (value: T, key: number, iter: this) => Iterable<M>,
context?: any
): Stack<M>;

Expand Down Expand Up @@ -2690,10 +2690,10 @@ declare module Immutable {
*
* Similar to `seq.map(...).flatten(true)`.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: any
): Seq.Keyed<KM, VM>;
): Seq.Keyed<any, any>;

/**
* Returns a new Seq with only the entries for which the `predicate`
Expand Down Expand Up @@ -3034,6 +3034,25 @@ declare module Immutable {
context?: any
): Seq<K, M>;

/**
* 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<M>(
mapper: (value: V, key: K, iter: this) => M,
context?: any
): Seq<M, M>;

/**
* Flat-maps the Seq, returning a Seq of the same type.
*
Expand All @@ -3044,6 +3063,17 @@ declare module Immutable {
context?: any
): Seq<K, M>;

/**
* Flat-maps the Seq, returning a Seq of the same type.
*
* Similar to `seq.map(...).flatten(true)`.
* Note: Used only for sets.
*/
flatMap<M>(
mapper: (value: V, key: K, iter: this) => Iterable<M>,
context?: any
): Seq<M, M>;

/**
* Returns a new Seq with only the values for which the `predicate`
* function returns true.
Expand Down Expand Up @@ -3965,6 +3995,25 @@ declare module Immutable {
context?: any
): Collection<K, M>;

/**
* 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<M, M> but are otherwise
* identical to normal `map()`.
*/
map<M>(
...args: never[]
): any;

/**
* Returns a new Collection of the same type with only the entries for which
* the `predicate` function returns true.
Expand Down Expand Up @@ -4264,6 +4313,17 @@ declare module Immutable {
context?: any
): Collection<K, M>;

/**
* Flat-maps the Collection, returning a Collection of the same type.
*
* Similar to `collection.map(...).flatten(true)`.
* Used for Dictionaries only.
*/
flatMap<KM, VM>(
mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
context?: any
): Collection<KM, VM>;

// Reducing a value

/**
Expand Down
19 changes: 10 additions & 9 deletions pages/lib/TypeKind.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 4 additions & 0 deletions pages/lib/genTypeDefData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading