diff --git a/.changeset/hot-vans-begin.md b/.changeset/hot-vans-begin.md new file mode 100644 index 0000000..0330050 --- /dev/null +++ b/.changeset/hot-vans-begin.md @@ -0,0 +1,5 @@ +--- +"@inversifyjs/core": minor +--- + +Updated `BindingToSyntax` with more flexible factory and provider constraints diff --git a/packages/container/libraries/container/src/binding/models/BindingFluentSyntax.ts b/packages/container/libraries/container/src/binding/models/BindingFluentSyntax.ts index 1712237..be3fe47 100644 --- a/packages/container/libraries/container/src/binding/models/BindingFluentSyntax.ts +++ b/packages/container/libraries/container/src/binding/models/BindingFluentSyntax.ts @@ -17,12 +17,14 @@ export interface BindToFluentSyntax { toConstantValue(value: T): BindWhenOnFluentSyntax; toDynamicValue(builder: DynamicValueBuilder): BindInWhenOnFluentSyntax; toFactory( - factory: T extends Factory + // eslint-disable-next-line @typescript-eslint/no-explicit-any + factory: T extends Factory ? (context: ResolutionContext) => T : never, ): BindWhenOnFluentSyntax; toProvider( - provider: T extends Provider + // eslint-disable-next-line @typescript-eslint/no-explicit-any + provider: T extends Provider ? (context: ResolutionContext) => T : never, ): BindWhenOnFluentSyntax; diff --git a/packages/container/libraries/container/src/binding/models/BindingFluentSyntaxImplementation.ts b/packages/container/libraries/container/src/binding/models/BindingFluentSyntaxImplementation.ts index 0a6c8e4..6beaa2a 100644 --- a/packages/container/libraries/container/src/binding/models/BindingFluentSyntaxImplementation.ts +++ b/packages/container/libraries/container/src/binding/models/BindingFluentSyntaxImplementation.ts @@ -178,7 +178,8 @@ export class BindToFluentSyntaxImplementation } public toFactory( - builder: T extends Factory + // eslint-disable-next-line @typescript-eslint/no-explicit-any + builder: T extends Factory ? (context: ResolutionContext) => T : never, ): BindWhenOnFluentSyntax { @@ -206,7 +207,8 @@ export class BindToFluentSyntaxImplementation } public toProvider( - provider: T extends Provider + // eslint-disable-next-line @typescript-eslint/no-explicit-any + provider: T extends Provider ? (context: ResolutionContext) => T : never, ): BindWhenOnFluentSyntax {