Skip to content

Commit ee97141

Browse files
refactor: fix linter errors
1 parent 53d6f13 commit ee97141

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/container-instance.class.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ export class ContainerInstance {
147147
*/
148148
getAsync<T>(identifier: ServiceIdentifier<T>): Promise<T> {
149149
const globalContainer = Container.of(undefined);
150-
let service = globalContainer.findService(identifier);
151-
let scopedService = this.findService(identifier);
150+
const service = globalContainer.findService(identifier);
151+
const scopedService = this.findService(identifier);
152152

153153
if (service && service.global === true) return this.getServiceValueAsync(identifier, service);
154154

@@ -472,7 +472,7 @@ export class ContainerInstance {
472472
if (service.factory instanceof Array) {
473473
// use special [Type, "create"] syntax to allow factory services
474474
// in this case Type instance will be obtained from Container and its method "create" will be called
475-
value = ((await this.getAsync(service.factory[0])) as any)[service.factory[1]](...params);
475+
value = (await this.getAsync(service.factory[0]))[service.factory[1]](...params);
476476
} else {
477477
// regular factory function
478478
value = service.factory(...params, this);
@@ -488,6 +488,7 @@ export class ContainerInstance {
488488
// need to be injected, and user can use provided container to get instances he needs
489489
params.push(this);
490490

491+
// eslint-disable-next-line prefer-spread
491492
value = new (type.bind.apply(type, params))();
492493
}
493494

src/error/MissingInitializedPromiseError.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22
* Thrown when user improperly uses the asyncInitialization Service option.
33
*/
44
export class MissingInitializedPromiseError extends Error {
5-
name = "MissingInitializedPromiseError";
5+
name = 'MissingInitializedPromiseError';
66

7-
constructor(value: any) {
8-
super(
9-
(value.initialized
10-
? `asyncInitialization: true was used, but ${value.name}#initialized is not a Promise. `
11-
: `asyncInitialization: true was used, but ${value.name}#initialized is undefined. `) +
12-
`You will need to either extend the abstract AsyncInitializedService class, or assign ` +
13-
`${value.name}#initialized to a Promise in your class' constructor that resolves when all required ` +
14-
`initialization is complete.`
15-
);
16-
Object.setPrototypeOf(this, MissingInitializedPromiseError.prototype);
17-
}
7+
// TODO: User proper type
8+
constructor(value: { name: string; initialized: boolean }) {
9+
super(
10+
(value.initialized
11+
? `asyncInitialization: true was used, but ${value.name}#initialized is not a Promise. `
12+
: `asyncInitialization: true was used, but ${value.name}#initialized is undefined. `) +
13+
`You will need to either extend the abstract AsyncInitializedService class, or assign ` +
14+
`${value.name}#initialized to a Promise in your class' constructor that resolves when all required ` +
15+
`initialization is complete.`
16+
);
17+
Object.setPrototypeOf(this, MissingInitializedPromiseError.prototype);
18+
}
1819
}

src/types/AsyncInitializedService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* Extend when declaring a service with asyncInitialization: true flag.
33
*/
44
export abstract class AsyncInitializedService {
5-
public initialized: Promise<any>;
5+
public initialized: Promise<any>;
66

7-
constructor() {
8-
this.initialized = this.initialize();
9-
}
7+
constructor() {
8+
this.initialized = this.initialize();
9+
}
1010

11-
protected abstract initialize(): Promise<any>;
11+
protected abstract initialize(): Promise<any>;
1212
}

0 commit comments

Comments
 (0)