@injectable-ts/core
Version:
Purely-functional strictly-typed IoC/DI for TypeScript
21 lines (20 loc) • 1.17 kB
TypeScript
import { Flatten, Injectable, UnknownDependencyTree } from './injectable';
type OmitInChildren<Children extends readonly UnknownDependencyTree[], Keys> = {
readonly [Index in keyof Children]: OmitDependencies<Children[Index], Keys>;
};
export type Step<Tree extends UnknownDependencyTree, Keys> = {
readonly type: Tree['type'];
readonly name: Tree['name'];
readonly optional: Tree['optional'];
readonly children: OmitInChildren<Tree['children'], Keys>;
};
type OmitDependencies<Tree, Keys> = Tree extends UnknownDependencyTree ? Tree['name'] extends never ? Step<Tree, Keys> : Tree['name'] extends Keys ? never : Step<Tree, Keys> : never;
interface ProvideFn {
<Dependencies extends UnknownDependencyTree, Value>(input: Injectable<Dependencies, Value>): <Keys extends keyof Flatten<Dependencies>>() => Injectable<{
readonly [Key in keyof OmitDependencies<Dependencies, Keys>]: OmitDependencies<Dependencies, Keys>[Key];
}, (innerDependencies: {
readonly [Key in keyof Flatten<Dependencies> as Key extends Keys ? Key : never]: Flatten<Dependencies>[Key];
}) => Value>;
}
export declare const provide: ProvideFn;
export {};