##// END OF EJS Templates
working on IoC configuration
working on IoC configuration

File last commit:

r112:efce7387bfc8 ioc ts support
r113:22cf333c0b34 ioc ts support
Show More
Annotations.ts
41 lines | 1.3 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / di / Annotations.ts
cin
Initial work on typescript support for the container configuration
r107 import { Constructor } from "../interfaces";
export interface InjectOptions {
lazy?: boolean;
}
cin
dependency builder proposal
r108 type Setter<T = any> = (v: T) => void;
cin
working on di decorators
r109 type Compatible<T1, T2> = T1 extends T2 ? any : never;
type SetterType<T> = T extends (v: infer V) => void ? V : never;
cin
Working on IoC container configuration
r111 type ExtractService<K, S> = K extends keyof S ? S[K] : K;
cin
working on di decorators
r109
cin
Working on IoC container configuration
r111 type ExtractDependency<D, S> = D extends { $dependency: infer K } ? D extends { lazy: true } ? () => ExtractService<K, S> : ExtractService<K, S> : VisitDependency<D, S>;
cin
working on di decorators
r109
cin
Working on IoC container configuration
r111 type VisitDependency<D, S> = D extends {} ? { [K in keyof D]: ExtractDependency<D[K], S> } : D;
cin
working on di decorators
r109
cin
dependency builder proposal
r108 export class Builder<T, S> {
cin
Working on IoC container configuration
r111 consume<P extends any[]>(...args: P) {
return <C extends new (...args: ExtractDependency<P, S>) => T>(constructor: C) => {
cin
Working on IoC container configuration
r112 return constructor as typeof constructor & { service: () => T };
cin
dependency builder proposal
r108 };
}
inject<K extends keyof S>(dependency: K) {
cin
working on di decorators
r109 // K = "bar"
// M = "setValue"
// S[K] = Bar
// T[M] = (value: string) => void
// P[m] = (value: V) => void
return <P, M extends keyof (T | P)>(target: P, memberName: M, descriptor: TypedPropertyDescriptor<Compatible<T[M], Setter<S[K]>>>) => {
cin
dependency builder proposal
r108
};
}
cin
Working on IoC container configuration
r112 cast<T2 extends T>(): Builder<T2, S> {
return this as Builder<T2, S>;
}
cin
dependency builder proposal
r108 }