config.ts
38 lines
| 1.0 KiB
| video/mp2t
|
TypeScriptLexer
|
|
r110 | import { Foo } from "./Foo"; | ||
| import { Bar } from "./Bar"; | ||||
| import { Box } from "./Box"; | ||||
|
|
r116 | import { primitive } from "../safe"; | ||
| import { Constructor } from "../interfaces"; | ||||
|
|
r111 | |||
|
|
r116 | interface Services { | ||
|
|
r110 | foo: Foo; | ||
| bar: Bar; | ||||
|
|
r116 | box: Box<Foo>; | ||
| host: string; | ||||
|
|
r110 | |||
|
|
r116 | } | ||
|
|
r110 | |||
|
|
r116 | interface TypeDescriptor<T, C extends Constructor<T>> { | ||
| $type: C; | ||||
| params: Wrap<ConstructorParameters<C>>; | ||||
|
|
r110 | } | ||
|
|
r116 | function typeRegistration<T, C extends Constructor<T>>(target: C, params: Wrap<ConstructorParameters<C>>): TypeDescriptor<T, C> { | ||
| throw new Error(); | ||||
| } | ||||
|
|
r111 | |||
|
|
r117 | declare function register<T>(): { type<C extends Constructor<T>>(target: C, params: Wrap<ConstructorParameters<C>>): TypeDescriptor<T, C>}; | ||
|
|
r116 | type Wrap<T> = T extends primitive ? T : | ||
| { [k in keyof T]: Wrap<T[k]> } | TypeDescriptor<T, Constructor<T>>; | ||||
|
|
r111 | |||
|
|
r116 | const config: Wrap<Services> = { | ||
| foo: typeRegistration(Foo, []), | ||||
| bar: typeRegistration(Bar, [{ foo: null as any, nested: null as any }]), | ||||
|
|
r117 | box: register<Box<Foo>>().type(Box, [{ $type: Bar, params: [] }]), | ||
|
|
r116 | host: "" | ||
|
|
r111 | }; | ||
