fixes typing

This commit is contained in:
Robin Chappatte
2024-05-31 18:05:13 +02:00
parent cc31065348
commit 744d1eb6ef
2 changed files with 8 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
type Provider<T> = (manager: DependencyManager) => Promise<T> | T;
type ClassType<T> = new () => T;
type HasConstructor<T> = T extends new (...args: any[]) => unknown ? T : never;
type ConstructorInstance<T> = T extends new (...args: any[]) => infer I ? I
: never;
// deno-lint-ignore no-explicit-any
type ModuleIdentifier = any;
@@ -41,7 +43,9 @@ export class DependencyManager {
*
* @param identifier the identifier used to register the provider
*/
async resolve<T>(identifier: ClassType<T>): Promise<T>;
async resolve<T>(
identifier: HasConstructor<T>,
): Promise<ConstructorInstance<T>>;
async resolve<T>(identifier: ModuleIdentifier): Promise<T>;
async resolve(identifier: ModuleIdentifier) {
const module = this.modules.get(identifier);