@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 +1 -1
- package/src/builtins.ts +28 -29
- package/src/nominal.ts +4 -3
package/package.json
CHANGED
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
|
-
|
|
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:
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export function set<K, V>(map: AnyMap<K, V>, key: K, value: V) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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`.
|