@naturalcycles/js-lib 15.69.0 → 15.70.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/promise/pProps.js +0 -2
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
- package/src/promise/pProps.ts +1 -5
- package/src/types.ts +10 -0
package/dist/promise/pProps.js
CHANGED
|
@@ -14,7 +14,5 @@
|
|
|
14
14
|
*/
|
|
15
15
|
export async function pProps(input) {
|
|
16
16
|
const keys = Object.keys(input);
|
|
17
|
-
// `as any` here is added to make it compile when `noUncheckedIndexedAccess` is false
|
|
18
|
-
// oxlint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
19
17
|
return Object.fromEntries((await Promise.all(Object.values(input))).map((v, i) => [keys[i], v]));
|
|
20
18
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -84,6 +84,14 @@ export type AnyAsyncFunction<T = any> = (...args: any[]) => Promise<T>;
|
|
|
84
84
|
export type AsyncFunction<T = any> = () => Promise<T>;
|
|
85
85
|
export type AnyPromisableFunction<T = any> = (...args: any[]) => Promisable<T>;
|
|
86
86
|
export type PromisableFunction<T = any> = () => Promisable<T>;
|
|
87
|
+
export type AnySyncFunction<T = any> = (...args: any[]) => NotPromise<T>;
|
|
88
|
+
export type SyncFunction<T = any> = () => NotPromise<T>;
|
|
89
|
+
/**
|
|
90
|
+
* Compile-time guard against accidentally returning a Promise from a sync context.
|
|
91
|
+
* Example usage: `fn: () => NotPromise<T>`
|
|
92
|
+
* This would fail if fn returns a Promise (e.g an async function).
|
|
93
|
+
*/
|
|
94
|
+
export type NotPromise<T> = [T] extends [PromiseLike<any>] ? never : T;
|
|
87
95
|
/**
|
|
88
96
|
* A function that lazily calculates something.
|
|
89
97
|
*/
|
package/package.json
CHANGED
package/src/promise/pProps.ts
CHANGED
|
@@ -16,9 +16,5 @@ export async function pProps<T>(input: { [K in keyof T]: T[K] | Promise<T[K]> })
|
|
|
16
16
|
[K in keyof T]: Awaited<T[K]>
|
|
17
17
|
}> {
|
|
18
18
|
const keys = Object.keys(input)
|
|
19
|
-
|
|
20
|
-
// oxlint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
21
|
-
return Object.fromEntries(
|
|
22
|
-
(await Promise.all(Object.values(input))).map((v, i) => [keys[i], v]),
|
|
23
|
-
) as any
|
|
19
|
+
return Object.fromEntries((await Promise.all(Object.values(input))).map((v, i) => [keys[i], v]))
|
|
24
20
|
}
|
package/src/types.ts
CHANGED
|
@@ -105,6 +105,16 @@ export type AnyAsyncFunction<T = any> = (...args: any[]) => Promise<T>
|
|
|
105
105
|
export type AsyncFunction<T = any> = () => Promise<T>
|
|
106
106
|
export type AnyPromisableFunction<T = any> = (...args: any[]) => Promisable<T>
|
|
107
107
|
export type PromisableFunction<T = any> = () => Promisable<T>
|
|
108
|
+
export type AnySyncFunction<T = any> = (...args: any[]) => NotPromise<T>
|
|
109
|
+
export type SyncFunction<T = any> = () => NotPromise<T>
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Compile-time guard against accidentally returning a Promise from a sync context.
|
|
113
|
+
* Example usage: `fn: () => NotPromise<T>`
|
|
114
|
+
* This would fail if fn returns a Promise (e.g an async function).
|
|
115
|
+
*/
|
|
116
|
+
export type NotPromise<T> = [T] extends [PromiseLike<any>] ? never : T
|
|
117
|
+
|
|
108
118
|
/**
|
|
109
119
|
* A function that lazily calculates something.
|
|
110
120
|
*/
|