From eaa6033f659e63bcc2dac39c4176f4dd251d658d Mon Sep 17 00:00:00 2001 From: Marco Weber Date: Tue, 8 Aug 2023 16:01:04 +0200 Subject: [PATCH] - improved tsconfig.json --- src/ServiceContainer.ts | 4 ++-- src/decorators.ts | 2 +- tests/decorators.test.ts | 1 + tsconfig.json | 5 ++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ServiceContainer.ts b/src/ServiceContainer.ts index bbeb88e..e90353d 100644 --- a/src/ServiceContainer.ts +++ b/src/ServiceContainer.ts @@ -24,7 +24,7 @@ export default { } if (!service.instance) { - service.instance = service.factory(); + service.instance = service.factory?.(); service.factory = undefined; } @@ -63,6 +63,6 @@ function getFactory(factoryOrClassReference: Factory | Function): Factory { type Factory = () => any; type Service = { - factory: () => any; + factory?: () => any; instance?: any; } diff --git a/src/decorators.ts b/src/decorators.ts index a6867a3..febe2be 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -7,7 +7,7 @@ export function inject(serviceIdOrTarget: Object | string, propertyKey?: string) }; } - redefineObject(serviceIdOrTarget, propertyKey); + redefineObject(serviceIdOrTarget, propertyKey!); } function redefineObject(target: Object, propertyKey: string, serviceId?: string) { diff --git a/tests/decorators.test.ts b/tests/decorators.test.ts index 5a020b6..2eaa6a4 100644 --- a/tests/decorators.test.ts +++ b/tests/decorators.test.ts @@ -26,6 +26,7 @@ describe('decorators', () => { inject(anObject, 'aService'); + // @ts-ignore expect(() => anObject.aService = jest.fn()).toThrow('Injected property [aService] can\'t be reset'); }); diff --git a/tsconfig.json b/tsconfig.json index 1d09eec..3aec876 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,7 +6,10 @@ "declaration": true, "esModuleInterop": true, "moduleResolution": "node", - "module": "commonjs" + "module": "commonjs", + "strict": true, + "noImplicitAny": true, + "strictPropertyInitialization": true }, "include": [ "src/**/*"