Skip to content

Commit

Permalink
BREAKING: Remove Iterable<T> as tuple from Map constructor types (#1626)
Browse files Browse the repository at this point in the history
These have caused more issues with typing than they fixed, unfortunately. While the runtime behavior is still supported, TypeScript types can't capture immutable List as Tuple.

Closes #1611
  • Loading branch information
leebyron committed Oct 27, 2018
1 parent 6203e2a commit 1d460e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 0 additions & 2 deletions type-definitions/Immutable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ declare module Immutable {
* not altered.
*/
export function Map<K, V>(collection: Iterable<[K, V]>): Map<K, V>;
export function Map<T>(collection: Iterable<Iterable<T>>): Map<T, T>;
export function Map<V>(obj: {[key: string]: V}): Map<string, V>;
export function Map<K, V>(): Map<K, V>;
export function Map(): Map<any, any>;
Expand Down Expand Up @@ -1419,7 +1418,6 @@ declare module Immutable {
* the `new` keyword during construction.
*/
export function OrderedMap<K, V>(collection: Iterable<[K, V]>): OrderedMap<K, V>;
export function OrderedMap<T>(collection: Iterable<Iterable<T>>): OrderedMap<T, T>;
export function OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>;
export function OrderedMap<K, V>(): OrderedMap<K, V>;
export function OrderedMap(): OrderedMap<any, any>;
Expand Down
17 changes: 7 additions & 10 deletions type-definitions/ts-tests/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ import { Map, List } from '../../';
// $ExpectType Map<{}, {}>
Map();

// $ExpectType Map<number, number>
Map([[1, 1]]);
// $ExpectType Map<number, string>
Map([[1, 'a']]);

// $ExpectType Map<number, string>
Map(List<[number, string]>([[1, 'a']]));

// $ExpectType Map<string, number>
Map({ a: 1 });

// $ExpectType Map<string, string>
Map(List.of(List(['a', 'b'])));

// $ExpectType Map<number, number>
Map(List.of(List([1, 2])));

// $ExpectType Map<string | number, string | number>
Map(List.of(List(['a', 1])));
// $ExpectError - TypeScript does not support Lists as tuples
Map(List([List(['a', 'b'])]));

// $ExpectError
const invalidNumberMap: Map<number, number> = Map();
Expand Down
17 changes: 7 additions & 10 deletions type-definitions/ts-tests/ordered-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ import { OrderedMap, List } from '../../';
// $ExpectType OrderedMap<{}, {}>
OrderedMap();

// $ExpectType OrderedMap<number, number>
OrderedMap([[1, 1]]);
// $ExpectType OrderedMap<number, string>
OrderedMap([[1, 'a']]);

// $ExpectType OrderedMap<number, string>
OrderedMap(List<[number, string]>([[1, 'a']]));

// $ExpectType OrderedMap<string, number>
OrderedMap({ a: 1 });

// $ExpectType OrderedMap<string, string>
OrderedMap(List.of(List(['a', 'b'])));

// $ExpectType OrderedMap<number, number>
OrderedMap(List.of(List([1, 2])));

// $ExpectType OrderedMap<string | number, string | number>
OrderedMap(List.of(List(['a', 1])));
// $ExpectError - TypeScript does not support Lists as tuples
OrderedMap(List([List(['a', 'b'])]));

// $ExpectError
const invalidNumberOrderedMap: OrderedMap<number, number> = OrderedMap();
Expand Down

0 comments on commit 1d460e2

Please sign in to comment.