Skip to content

Commit 03ca1ed

Browse files
committed
[typescript] Map constructor accept a list of string as key
1 parent 0e7d750 commit 03ca1ed

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

type-definitions/Immutable.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ declare module Immutable {
765765
export function Map<K, V>(): Map<K, V>;
766766
export function Map<K, V>(collection: Iterable<[K, V]>): Map<K, V>;
767767
export function Map<V>(obj: { [key: string]: V }): Map<string, V>;
768+
export function Map<K extends string, V>(obj: { [P in K]?: V }): Map<K, V>;
768769

769770
export interface Map<K, V> extends Collection.Keyed<K, V> {
770771
/**

type-definitions/ts-tests/map.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ import { Map, List } from '../../';
2626
// No longer works in typescript@>=3.9
2727
// // $ExpectError - TypeScript does not support Lists as tuples
2828
// Map(List([List(['a', 'b'])]));
29+
30+
// $ExpectError
31+
const invalidNumberMap: Map<number, number> = Map();
32+
33+
// $ExpectType Map<"status", string>
34+
Map<'status', string>({ status: 'paid' });
35+
36+
// $ExpectType Map<"status" | "amount", string>
37+
Map<'status' | 'amount', string>({ status: 'paid' });
38+
39+
// $ExpectError
40+
Map<'status', string>({ status: 'paid', amount: 10 });
2941
}
3042

3143
{

0 commit comments

Comments
 (0)