ts-map is a TypeScript library that provides a Map-like data structure, mirroring the functionality of the native ES6 Map object but explicitly designed for TypeScript environments. Its current stable version is 1.0.3, with no specific release cadence indicated beyond that. The library aims to offer a familiar API for key-value pair storage, where keys can be of any type (including objects), not just strings, which is a key differentiator from plain JavaScript objects. It supports generics for strong typing of both keys and values, enhancing type safety in TypeScript projects. While it replicates standard Map methods like `set`, `get`, `has`, `delete`, `clear`, `size`, `keys`, `values`, `entries`, and `forEach`, its primary distinction lies in its explicit TypeScript typing and design, which might appeal to developers looking for a fully typed alternative. It's important to note that object keys are compared by reference, mirroring ES6 Map behavior, which is a common gotcha for developers expecting value-based comparison.
npm install ts-mapVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic instantiation, setting various key types, retrieving values, iterating over map entries, and using generics for type safety.
Always use the exact same object or array instance when setting, getting, or deleting entries if you intend for them to be the same key. Avoid creating new instances (e.g., `map.get([1])` when `map.set([1], 'value')` was used with a different `[1]` array instance).
Always explicitly define generic types for keys and values, for example, `new TsMap<KeyType, ValueType>()`, to ensure the compiler enforces type constraints on map operations.
Ensure the value passed to the `set()` method matches the generic type `V` defined during `TsMap` instantiation (e.g., `new TsMap<number, Coder>()` requires `{ name: string }` objects for values).Use the ES module import syntax: `import TsMap from 'ts-map';` to correctly import the `TsMap` class.
No dependency data recorded yet.