##// END OF EJS Templates
improved interfaces and more tight type checking
improved interfaces and more tight type checking

File last commit:

r120:1b124b65514a ioc ts support
r120:1b124b65514a ioc ts support
Show More
Annotations.ts
77 lines | 2.2 KiB | video/mp2t | TypeScriptLexer
/ src / main / ts / di / Annotations.ts
cin
configuration interfaces moved to di/Configuration module...
r118 import { primitive } from "../safe";
cin
configuration draft-1
r119 import { TypeRegistration } from "./Configuration";
cin
Initial work on typescript support for the container configuration
r107
export interface InjectOptions {
lazy?: boolean;
}
cin
configuration draft-1
r119 export interface Dependency<K extends keyof any> {
cin
working on IoC configuration
r114 $dependency: K;
lazy?: boolean;
}
cin
configuration draft-1
r119 export interface Lazy<K extends keyof any> extends Dependency<K> {
cin
working on IoC configuration
r114 lazy: true;
}
cin
configuration draft-1
r119 type Compatible<T1, T2> = T2 extends T1 ? any : never;
cin
working on di decorators
r109
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
configuration interfaces moved to di/Configuration module...
r118 type ExtractDependency<D, S> = D extends { $dependency: infer K } ?
D extends { lazy: true } ? () => ExtractService<K, S> : ExtractService<K, S> :
WalkDependencies<D, S>;
cin
working on di decorators
r109
cin
configuration interfaces moved to di/Configuration module...
r118 type WalkDependencies<D, S> = D extends primitive ? D :
{ [K in keyof D]: ExtractDependency<D[K], S> };
cin
working on di decorators
r109
cin
improved interfaces and more tight type checking
r120 export class Builder<T, S extends object> {
cin
configuration draft-1
r119 declare<P extends any[]>(...args: P) {
cin
Working on IoC container configuration
r111 return <C extends new (...args: ExtractDependency<P, S>) => T>(constructor: C) => {
cin
improved interfaces and more tight type checking
r120
cin
dependency builder proposal
r108 };
}
cin
configuration interfaces moved to di/Configuration module...
r118 inject<P extends any[]>(...args: P) {
cin
working on di decorators
r109 // K = "bar"
// M = "setValue"
// S[K] = Bar
// T[M] = (value: string) => void
// P[m] = (value: V) => void
cin
configuration interfaces moved to di/Configuration module...
r118 return <X extends { [m in M]: (...args: any) => any }, M extends keyof (T | X)>(
target: X,
memberName: M,
descriptor: TypedPropertyDescriptor<Compatible<(...args: ExtractDependency<P, S>) => any, T[M]>>
) => {
cin
dependency builder proposal
r108
};
}
cin
configuration draft-1
r119 getDescriptor(): TypeRegistration<T, any, S> {
cin
configuration interfaces moved to di/Configuration module...
r118 throw new Error();
}
cin
configuration draft-1
r119 }
cin
improved interfaces and more tight type checking
r120 interface Declaration<S extends object> {
cin
configuration draft-1
r119 define<T>(): Builder<T, S>;
dependency<K extends keyof S>(name: K, opts: { lazy: true }): Lazy<K>;
dependency<K extends keyof S>(name: K, opts?: any): Dependency<K>;
config(): Config<S>;
}
cin
configuration interfaces moved to di/Configuration module...
r118
cin
improved interfaces and more tight type checking
r120 type ServiceModule<T, S extends object, M extends string = "service"> = {
[m in M]: Builder<T, S>;
};
cin
configuration interfaces moved to di/Configuration module...
r118
cin
improved interfaces and more tight type checking
r120 export interface Config<S extends object, Y extends keyof S = keyof S> {
register<K extends Y>(name: K, builder: Builder<S[K], S>): Config<S, Exclude<Y, K>>;
register<K extends Y>(name: K, m: Promise<ServiceModule<S[K], S>>): Config<S, Exclude<Y, K>>;
register<K extends Y, M extends string>(name: K, m: Promise<ServiceModule<S[K], S, M>>, x: M): Config<S, Exclude<Y, K>>;
cin
dependency builder proposal
r108 }
cin
configuration draft-1
r119
export declare function declare<S extends object>(): Declaration<S>;