udic 1.1.0 → 1.2.1
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/index.d.ts +6 -6
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
declare const _t: unique symbol;
|
|
2
2
|
declare const _d: unique symbol;
|
|
3
|
-
type
|
|
3
|
+
type UnionToIntersect<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
4
4
|
type UnwrapReturn<T> = T extends () => infer R ? R : T;
|
|
5
|
-
type
|
|
5
|
+
type Evaluate<T> = { [K in keyof T] : T[K] } & {};
|
|
6
6
|
type List<T> = [T, ...T[]];
|
|
7
7
|
export type Dependency = (() => Service) | Compute;
|
|
8
|
-
export type TDependency<T extends Dependency | Impl> =
|
|
8
|
+
export type TDependency<T extends Dependency | Impl> = UnionToIntersect<UnwrapReturn<T>[typeof _d]>;
|
|
9
9
|
export type TResult<T extends Dependency | Impl> = UnwrapReturn<T>[typeof _t];
|
|
10
10
|
export interface Service<
|
|
11
11
|
K extends string = any,
|
|
@@ -41,7 +41,7 @@ export declare const service: <const T extends string>(name: T) => (<K>() => Ser
|
|
|
41
41
|
* @param f
|
|
42
42
|
*/
|
|
43
43
|
export declare const use: <
|
|
44
|
-
const T extends List<
|
|
44
|
+
const T extends List<Dependency>,
|
|
45
45
|
R
|
|
46
46
|
>(deps: T, f: (...args: { [K in keyof T] : TResult<T[K]> }) => R) => Compute<TDependency<T[number]>, R>;
|
|
47
47
|
/**
|
|
@@ -53,7 +53,7 @@ export declare const inject: <
|
|
|
53
53
|
T,
|
|
54
54
|
R,
|
|
55
55
|
D extends Partial<T>
|
|
56
|
-
>(compute: Compute<T, R>, d: D) => Compute<
|
|
56
|
+
>(compute: Compute<T, R>, d: D) => Compute<Evaluate<Omit<T, keyof D>>, R>;
|
|
57
57
|
/**
|
|
58
58
|
* Create an implementation of the service that depends on other services
|
|
59
59
|
* @param service
|
|
@@ -72,5 +72,5 @@ export declare const impl: <
|
|
|
72
72
|
export declare const link: <
|
|
73
73
|
const T extends List<Impl>,
|
|
74
74
|
D extends TDependency<T[number]>
|
|
75
|
-
>(impls: T, deps: D) =>
|
|
75
|
+
>(impls: T, deps: D) => Evaluate<D & UnionToIntersect<TResult<T[number]>>>;
|
|
76
76
|
export {};
|