From 632d13dd064100e86f82a1dbd9073863266aee18 Mon Sep 17 00:00:00 2001 From: Jason <574469551@qq.com> Date: Fri, 24 Jun 2022 15:26:11 +0800 Subject: [PATCH] Improve type infererence for Map --- type-definitions/immutable.d.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/type-definitions/immutable.d.ts b/type-definitions/immutable.d.ts index a8c62e1d7..20c512d27 100644 --- a/type-definitions/immutable.d.ts +++ b/type-definitions/immutable.d.ts @@ -759,11 +759,15 @@ declare namespace Immutable { * but since Immutable Map keys can be of any type the argument to `get()` is * not altered. */ - function Map(collection?: Iterable<[K, V]>): Map; - function Map(obj: { [key: string]: V }): Map; - function Map(obj: { [P in K]?: V }): Map; - - interface Map extends Collection.Keyed { + function Map>(collection: T): Map<{ + [P in T[number]as P[0]]: P[1] + }>; + function Map(obj: T): (T extends Map + ? T + : Map); + + interface Map extends IterableMap { } + interface IterableMap extends Collection.Keyed { /** * The number of entries in this Map. */