From 4cad768b0ceeff1dc739ca716eae19d93f6c1a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincent=20Fran=C3=A7ois?= Date: Mon, 16 Sep 2024 18:45:55 +0200 Subject: [PATCH] feat: add HashMap.HashMap.Entry utility type (#3618) --- .changeset/chilled-hotels-sniff.md | 5 +++++ packages/effect/dtslint/HashMap.ts | 10 +++++++++- packages/effect/src/HashMap.ts | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .changeset/chilled-hotels-sniff.md diff --git a/.changeset/chilled-hotels-sniff.md b/.changeset/chilled-hotels-sniff.md new file mode 100644 index 0000000000..8aa434d4b6 --- /dev/null +++ b/.changeset/chilled-hotels-sniff.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +Adds HashMap.HashMap.Entry type helper diff --git a/packages/effect/dtslint/HashMap.ts b/packages/effect/dtslint/HashMap.ts index 00ed98ce10..ed8c53bc8d 100644 --- a/packages/effect/dtslint/HashMap.ts +++ b/packages/effect/dtslint/HashMap.ts @@ -1,6 +1,7 @@ -import { pipe } from "effect/Function" +import { hole, pipe } from "effect/Function" import * as HashMap from "effect/HashMap" import * as Predicate from "effect/Predicate" +import type * as Types from "effect/Types" declare const hmLiterals: HashMap.HashMap<"k", "v"> declare const numbers: HashMap.HashMap @@ -23,6 +24,13 @@ export type K = HashMap.HashMap.Key // $ExpectType "v" export type V = HashMap.HashMap.Value +// ------------------------------------------------------------------------------------- +// HashMap.Entry +// ------------------------------------------------------------------------------------- + +// $ExpectType ["k", "v"] +hole>>() + // ------------------------------------------------------------------------------------- // filter // ------------------------------------------------------------------------------------- diff --git a/packages/effect/src/HashMap.ts b/packages/effect/src/HashMap.ts index 47f3597112..f5a881f727 100644 --- a/packages/effect/src/HashMap.ts +++ b/packages/effect/src/HashMap.ts @@ -66,6 +66,22 @@ export declare namespace HashMap { * @category type-level */ export type Value> = [T] extends [HashMap] ? _V : never + + /** + * This type-level utility extracts the entry type `[K, V]` from a `HashMap` type. + * + * @example + * import { HashMap } from "effect" + * + * declare const hm: HashMap.HashMap + * + * // $ExpectType [string, number] + * type V = HashMap.HashMap.Entry + * + * @since 3.9.0 + * @category type-level + */ + export type Entry> = [Key, Value] } /**