Package: effect
Module: TxHashMap
Extracts the key type from a TxHashMap type.
Example (Extracting key types)
import { Effect, TxHashMap } from "effect"
const program = Effect.gen(function*() {
// Create a user map to extract key type from
const userMap = yield* TxHashMap.make(
["alice", { name: "Alice", age: 30 }],
["bob", { name: "Bob", age: 25 }]
)
// Extract the key type (string)
type UserKey = TxHashMap.TxHashMap.Key<typeof userMap>
// Use the extracted type in functions
const getUserById = (id: UserKey) => TxHashMap.get(userMap, id)
const alice = yield* getUserById("alice") // Option<{ name: string, age: number }>
})
Signature
type Key<T> = T extends TxHashMap<infer K, any> ? K : never
Since v4.0.0