1.4.1 • Published 8 months ago

@jfromaniello/typedmap v1.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Typescript strongly typed Map.

Typescript comes with a generic Map<K, V> type which allows you to set a fixed type for the Keys and another for the Values. This is enough for most cases but sometimes you need more granularity as to which tuples are allowed in the map.

Installation

npm install @jfromaniello/typedmap

Usage

import { TypedMap } from '@jfromaniello/typedmap';

type KeyValue =
  ['foo' | 'bar', string] |
  [number, string] |
  ['person', Person];

const map = new TypedMap<KeyValue>();

// Valid examples
map.set('foo', 'hello');
map.set(1, 'world');
map.set('person', new Person());

// Invalid examples
// new Map([['person', 123]]);
// map.set('foo', 'test');
// map.get('fiii');

License

MIT - 2024 José F. Romaniello

1.4.1

8 months ago

1.4.0

1 year ago

1.3.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago