@sidex/types 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@sidex/types",
3
3
  "author": "Silitics GmbH <info@silitics.com>",
4
4
  "license": "(MIT or Apache-2.0)",
5
- "version": "0.0.4",
5
+ "version": "0.0.5",
6
6
  "description": "",
7
7
  "main": "src/index.ts",
8
8
  "types": "./src/index.ts",
package/src/builtins.ts CHANGED
@@ -242,10 +242,9 @@ export type EntriesMap<K, V> = [K, V][]
242
242
  */
243
243
  export type ObjectMap<K extends string, V> = { [key in K]?: V }
244
244
 
245
- /**
246
- * A map.
247
- */
248
- export type AnyMap<K, V> = K extends string ? ObjectMap<K, V> : EntriesMap<K, V>
245
+ export function entries<K extends string, V>(map: ObjectMap<K, V>): [K, V][]
246
+
247
+ export function entries<K, V>(map: EntriesMap<K, V>): [K, V][]
249
248
 
250
249
  /**
251
250
  * The entries of the map.
@@ -253,7 +252,7 @@ export type AnyMap<K, V> = K extends string ? ObjectMap<K, V> : EntriesMap<K, V>
253
252
  * @param map
254
253
  * @returns
255
254
  */
256
- export function entries<K, V>(map: AnyMap<K, V>): [K, V][] {
255
+ export function entries<K, V>(map: any): any {
257
256
  if (Array.isArray(map)) {
258
257
  return map
259
258
  } else {
@@ -273,27 +272,27 @@ function getIndexMap<K, V>(map: EntriesMap<K, V>): Map<K, number> {
273
272
  }
274
273
  }
275
274
 
276
- export function get<K, V>(map: AnyMap<K, V>, key: K): V | undefined {
277
- if (Array.isArray(map)) {
278
- const index = getIndexMap(map).get(key)
279
- return index === undefined ? undefined : (map[index] as [K, V])[1]
280
- } else {
281
- return (map as ObjectMap<any, V>)[key]
282
- }
283
- }
284
-
285
- export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
286
- if (Array.isArray(map)) {
287
- const indexMap = getIndexMap(map)
288
- const existingIndex = indexMap.get(key)
289
- if (existingIndex !== undefined) {
290
- map[existingIndex] = [key, value]
291
- } else {
292
- const index = map.length
293
- map.push([key, value])
294
- indexMap.set(key, index)
295
- }
296
- } else {
297
- return (map as ObjectMap<any, V>)[key]
298
- }
299
- }
275
+ // export function get<K, V>(map: AnyMap<K, V>, key: K): V | undefined {
276
+ // if (Array.isArray(map)) {
277
+ // const index = getIndexMap(map).get(key)
278
+ // return index === undefined ? undefined : (map[index] as [K, V])[1]
279
+ // } else {
280
+ // return (map as ObjectMap<any, V>)[key]
281
+ // }
282
+ // }
283
+
284
+ // export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
285
+ // if (Array.isArray(map)) {
286
+ // const indexMap = getIndexMap(map)
287
+ // const existingIndex = indexMap.get(key)
288
+ // if (existingIndex !== undefined) {
289
+ // map[existingIndex] = [key, value]
290
+ // } else {
291
+ // const index = map.length
292
+ // map.push([key, value])
293
+ // indexMap.set(key, index)
294
+ // }
295
+ // } else {
296
+ // return (map as ObjectMap<any, V>)[key]
297
+ // }
298
+ // }
package/src/nominal.ts CHANGED
@@ -3,12 +3,13 @@
3
3
  */
4
4
  declare const SIDEX_PATH_SYMBOL: unique symbol
5
5
 
6
+ // This type improves error messages.
7
+ type N<P extends string> ={ [SIDEX_PATH_SYMBOL]: { [key in P]: null } }
8
+
6
9
  /**
7
10
  * A nominal type based on `T` and identified by it's Sidex path `P`.
8
11
  */
9
- export type Nominal<T, P extends string> = T & {
10
- [SIDEX_PATH_SYMBOL]: { [key in P]: null }
11
- }
12
+ export type Nominal<T, P extends string> = T & N<P>
12
13
 
13
14
  /**
14
15
  * The structural type of a nominal type `T`.