@naturalcycles/js-lib 15.48.1 → 15.49.0

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/dist/types.d.ts CHANGED
@@ -288,17 +288,23 @@ export declare const _stringMapValues: <T>(map: StringMap<T>) => T[];
288
288
  */
289
289
  export declare const _stringMapEntries: <T>(map: StringMap<T>) => [k: string, v: T][];
290
290
  /**
291
- * Alias of `Object.keys`, but returns keys typed as `keyof T`, not as just `string`.
291
+ * Resolves to a string literal union of the keys of T, meaning they are
292
+ * always keys of T and always strings (never numbers or symbols).
293
+ */
294
+ export type ObjectKey<T> = `${Extract<keyof T, string | number>}`;
295
+ /**
296
+ * Alias of `Object.keys`, but returns keys with a string type that's as
297
+ * narrow as possible.
292
298
  * This is how TypeScript should work, actually.
293
299
  */
294
- export declare const _objectKeys: <T extends AnyObject>(obj: T) => (keyof T)[];
300
+ export declare const _objectKeys: <T extends AnyObject>(obj: T) => ObjectKey<T>[];
295
301
  /**
296
302
  * Alias of `Object.entries`, but returns better-typed output.
297
303
  *
298
304
  * So e.g you can use _objectEntries(obj).map([k, v] => {})
299
305
  * and `k` will be `keyof obj` instead of generic `string`.
300
306
  */
301
- export declare const _objectEntries: <T extends AnyObject>(obj: T) => [k: keyof T, v: T[keyof T]][];
307
+ export declare const _objectEntries: <T extends AnyObject>(obj: T) => [k: ObjectKey<T>, v: T[ObjectKey<T>]][];
302
308
  export type NullishValue = null | undefined;
303
309
  export type FalsyValue = false | '' | 0 | null | undefined;
304
310
  /**
package/dist/types.js CHANGED
@@ -31,7 +31,8 @@ export const _stringMapValues = Object.values;
31
31
  */
32
32
  export const _stringMapEntries = Object.entries;
33
33
  /**
34
- * Alias of `Object.keys`, but returns keys typed as `keyof T`, not as just `string`.
34
+ * Alias of `Object.keys`, but returns keys with a string type that's as
35
+ * narrow as possible.
35
36
  * This is how TypeScript should work, actually.
36
37
  */
37
38
  export const _objectKeys = Object.keys;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.48.1",
4
+ "version": "15.49.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "undici": "^7",
package/src/types.ts CHANGED
@@ -361,10 +361,17 @@ export const _stringMapValues = Object.values as <T>(map: StringMap<T>) => T[]
361
361
  export const _stringMapEntries = Object.entries as <T>(map: StringMap<T>) => [k: string, v: T][]
362
362
 
363
363
  /**
364
- * Alias of `Object.keys`, but returns keys typed as `keyof T`, not as just `string`.
364
+ * Resolves to a string literal union of the keys of T, meaning they are
365
+ * always keys of T and always strings (never numbers or symbols).
366
+ */
367
+ export type ObjectKey<T> = `${Extract<keyof T, string | number>}`
368
+
369
+ /**
370
+ * Alias of `Object.keys`, but returns keys with a string type that's as
371
+ * narrow as possible.
365
372
  * This is how TypeScript should work, actually.
366
373
  */
367
- export const _objectKeys = Object.keys as <T extends AnyObject>(obj: T) => (keyof T)[]
374
+ export const _objectKeys = Object.keys as <T extends AnyObject>(obj: T) => ObjectKey<T>[]
368
375
 
369
376
  /**
370
377
  * Alias of `Object.entries`, but returns better-typed output.
@@ -374,7 +381,7 @@ export const _objectKeys = Object.keys as <T extends AnyObject>(obj: T) => (keyo
374
381
  */
375
382
  export const _objectEntries = Object.entries as <T extends AnyObject>(
376
383
  obj: T,
377
- ) => [k: keyof T, v: T[keyof T]][]
384
+ ) => [k: ObjectKey<T>, v: T[ObjectKey<T>]][]
378
385
 
379
386
  export type NullishValue = null | undefined
380
387
  export type FalsyValue = false | '' | 0 | null | undefined