# HG changeset patch # User cin # Date 2022-05-23 08:51:26 # Node ID 154d88dba49c476908cf80d3ab322ae3a60e9960 # Parent a51ea59f042305d0df920608d2f6a0ffbb2967d2 code comments diff --git a/src/main/ts/FluentConfiguration.ts b/src/main/ts/FluentConfiguration.ts --- a/src/main/ts/FluentConfiguration.ts +++ b/src/main/ts/FluentConfiguration.ts @@ -1,21 +1,41 @@ import { DescriptorBuilder } from "./DescriptorBuilder"; -import { ConfigurableKeys, ContainerServices, ConfigurableServices, RegistrationBuildersMap, RequiredKeys } from "./interfaces"; +import { ConfigurableKeys, ContainerServices, ConfigurableServices, RegistrationBuildersMap, ExtractRequired } from "./interfaces"; import { ServiceContainer } from "./interfaces"; import { argumentNotNull, each, isKey } from "./traits"; export class FluentConfiguration = ConfigurableKeys> { - _builders: Partial> = {}; + private _builders: Partial> = {}; + /** Adds a declaration of the services to the current config. + * + * @template D The map of the services + * @returns self + */ declare>>(): FluentConfiguration> { return this as FluentConfiguration>; } + /** Adds compile-time information about the already provided services + * + * @template P The map of the provided services + * @returns self + */ provided

>(): FluentConfiguration> { return this as FluentConfiguration>; } + /** Register the service. + * + * @param name The name of the service + * @param builder The service builder + * @returns self + */ register(name: K, builder: RegistrationBuildersMap[K]): FluentConfiguration>; + /** Registers the collection of services + * @param config The collection of services to register. + * @returns self + */ register(config: RegistrationBuildersMap): FluentConfiguration>; register(nameOrConfig: K | RegistrationBuildersMap, builder?: RegistrationBuildersMap[K]) { if (isKey(nameOrConfig)) { @@ -28,9 +48,16 @@ export class FluentConfiguration>; } - done(missing: RequiredKeys extends never ? void : RequiredKeys) { - if (missing !== undefined) - throw new Error("The configuration isn't complete"); + /** + * This method is used to enable a compile time check of the configuration. + * If there are not configured services in the configuration the compiler + * will trigger the error. + * + * @param missing Empty object literal should always be specified. + * @returns self + */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars + done>(missing: M) { return this; } diff --git a/src/main/ts/interfaces.ts b/src/main/ts/interfaces.ts --- a/src/main/ts/interfaces.ts +++ b/src/main/ts/interfaces.ts @@ -117,5 +117,5 @@ export interface ILifetime { store(item: T, cleanup?: (item: T) => void): void; } -export type RequiredKeys = keyof { [p in K as (T[p] extends undefined ? never : p)]-?: T[p] }; +export type ExtractRequired = { [p in K as (undefined extends T[p] ? never : p)]-?: T[p] }; diff --git a/src/test/ts/t/container.ts b/src/test/ts/t/container.ts --- a/src/test/ts/t/container.ts +++ b/src/test/ts/t/container.ts @@ -49,7 +49,7 @@ const config = fluent() foo: it => it.factory($ => new Foo()), baz: it => it.value(new Foo()) }) - .done(); + .done({}); declare const container: Container;