diff --git a/.eslintrc.js b/.eslintrc.js index 052e905..6f9a7f2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,194 +1,194 @@ module.exports = { - "env": { - "browser": true, - "es6": true - }, - "extends": [ - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "./tsconfig.json", - "sourceType": "module" - }, - "plugins": [ - "eslint-plugin-import", - "eslint-plugin-prefer-arrow", - "eslint-plugin-jsdoc", - "@typescript-eslint" - ], - "rules": { - "@typescript-eslint/adjacent-overload-signatures": "error", - "@typescript-eslint/array-type": [ - "error", - { - "default": "array" - } - ], - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/ban-ts-comment": "error", - "@typescript-eslint/ban-types": [ - "error", - { - "types": { - "Object": { - "message": "Avoid using the `Object` type. Did you mean `object`?" - }, - "Function": { - "message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`." - }, - "Boolean": { - "message": "Avoid using the `Boolean` type. Did you mean `boolean`?" - }, - "Number": { - "message": "Avoid using the `Number` type. Did you mean `number`?" - }, - "String": { - "message": "Avoid using the `String` type. Did you mean `string`?" - }, - "Symbol": { - "message": "Avoid using the `Symbol` type. Did you mean `symbol`?" - } - } - } - ], - "@typescript-eslint/consistent-type-assertions": "error", - "@typescript-eslint/dot-notation": "error", - "@typescript-eslint/explicit-member-accessibility": [ - "off", - { - "accessibility": "explicit" - } - ], - "@typescript-eslint/explicit-module-boundary-types": "warn", - "@typescript-eslint/indent": "off", - "@typescript-eslint/member-ordering": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/no-array-constructor": "error", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-empty-interface": "error", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-extra-non-null-assertion": "error", - "@typescript-eslint/no-extra-semi": "error", - "@typescript-eslint/no-floating-promises": "off", - "@typescript-eslint/no-for-in-array": "error", - "@typescript-eslint/no-implied-eval": "error", - "@typescript-eslint/no-inferrable-types": "error", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-misused-promises": "error", - "@typescript-eslint/no-namespace": "error", - "@typescript-eslint/no-non-null-asserted-optional-chain": "error", - "@typescript-eslint/no-non-null-assertion": "warn", - "@typescript-eslint/no-parameter-properties": "off", - "@typescript-eslint/no-shadow": [ - "error", - { - "hoist": "all" - } - ], - "@typescript-eslint/no-this-alias": "error", - "@typescript-eslint/no-unnecessary-type-assertion": "error", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-call": "error", - "@typescript-eslint/no-unsafe-member-access": "error", - "@typescript-eslint/no-unsafe-return": "error", - "@typescript-eslint/no-unused-expressions": "error", - "@typescript-eslint/no-unused-vars": "warn", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/no-var-requires": "error", - "@typescript-eslint/prefer-as-const": "error", - "@typescript-eslint/prefer-for-of": "error", - "@typescript-eslint/prefer-function-type": "error", - "@typescript-eslint/prefer-namespace-keyword": "error", - "@typescript-eslint/prefer-regexp-exec": "error", - "@typescript-eslint/quotes": "off", - "@typescript-eslint/require-await": "error", - "@typescript-eslint/restrict-plus-operands": "error", - "@typescript-eslint/restrict-template-expressions": "error", - "@typescript-eslint/triple-slash-reference": [ - "error", - { - "path": "always", - "types": "prefer-import", - "lib": "always" - } - ], - "@typescript-eslint/unbound-method": "error", - "@typescript-eslint/unified-signatures": "error", - "arrow-parens": [ - "off", - "always" - ], - "brace-style": [ - "off", - "off" - ], - "comma-dangle": "off", - "complexity": "off", - "constructor-super": "error", - "curly": "off", - "dot-notation": "error", - "eqeqeq": [ - "error", - "smart" - ], - "guard-for-in": "error", - "id-blacklist": "off", - "id-match": "off", - "import/order": "off", - "indent": "off", - "jsdoc/check-alignment": "error", - "jsdoc/check-indentation": "off", - "jsdoc/newline-after-description": "error", - "max-classes-per-file": "off", - "max-len": "off", - "new-parens": "error", - "no-array-constructor": "off", - "no-bitwise": "error", - "no-caller": "error", - "no-cond-assign": "error", - "no-console": "warn", - "no-debugger": "error", - "no-empty": "off", - "no-empty-function": "off", - "no-eval": "error", - "no-extra-semi": "off", - "no-fallthrough": "off", - "no-implied-eval": "off", - "no-invalid-this": "off", - "no-new-wrappers": "error", - "no-shadow": "error", - "no-throw-literal": "error", - "no-trailing-spaces": "error", - "no-undef-init": "error", - "no-underscore-dangle": "off", - "no-unsafe-finally": "error", - "no-unused-expressions": "error", - "no-unused-labels": "error", - "no-unused-vars": "off", - "no-use-before-define": "off", - "no-var": "error", - "object-shorthand": "error", - "one-var": [ - "error", - "never" - ], - "prefer-arrow/prefer-arrow-functions": "off", - "prefer-const": "error", - "quotes": "off", - "radix": "error", - "require-await": "off", - "spaced-comment": [ - "error", - "always", - { - "markers": [ - "/" - ] - } - ], - "use-isnan": "error", - "valid-typeof": "off" - } + "env": { + "browser": true, + "es6": true + }, + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json", + "sourceType": "module" + }, + "plugins": [ + "eslint-plugin-import", + "eslint-plugin-prefer-arrow", + "eslint-plugin-jsdoc", + "@typescript-eslint" + ], + "rules": { + "@typescript-eslint/adjacent-overload-signatures": "error", + "@typescript-eslint/array-type": [ + "error", + { + "default": "array" + } + ], + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/ban-ts-comment": "error", + "@typescript-eslint/ban-types": [ + "error", + { + "types": { + "Object": { + "message": "Avoid using the `Object` type. Did you mean `object`?" + }, + "Function": { + "message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`." + }, + "Boolean": { + "message": "Avoid using the `Boolean` type. Did you mean `boolean`?" + }, + "Number": { + "message": "Avoid using the `Number` type. Did you mean `number`?" + }, + "String": { + "message": "Avoid using the `String` type. Did you mean `string`?" + }, + "Symbol": { + "message": "Avoid using the `Symbol` type. Did you mean `symbol`?" + } + } + } + ], + "@typescript-eslint/consistent-type-assertions": "error", + "@typescript-eslint/dot-notation": "error", + "@typescript-eslint/explicit-member-accessibility": [ + "off", + { + "accessibility": "explicit" + } + ], + "@typescript-eslint/explicit-module-boundary-types": "warn", + "@typescript-eslint/indent": "off", + "@typescript-eslint/member-ordering": "off", + "@typescript-eslint/naming-convention": "off", + "@typescript-eslint/no-array-constructor": "error", + "@typescript-eslint/no-empty-function": "off", + "@typescript-eslint/no-empty-interface": "error", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-extra-non-null-assertion": "error", + "@typescript-eslint/no-extra-semi": "error", + "@typescript-eslint/no-floating-promises": "off", + "@typescript-eslint/no-for-in-array": "error", + "@typescript-eslint/no-implied-eval": "error", + "@typescript-eslint/no-inferrable-types": "error", + "@typescript-eslint/no-misused-new": "error", + "@typescript-eslint/no-misused-promises": "error", + "@typescript-eslint/no-namespace": "error", + "@typescript-eslint/no-non-null-asserted-optional-chain": "error", + "@typescript-eslint/no-non-null-assertion": "warn", + "@typescript-eslint/no-parameter-properties": "off", + "@typescript-eslint/no-shadow": [ + "error", + { + "hoist": "all" + } + ], + "@typescript-eslint/no-this-alias": "error", + "@typescript-eslint/no-unnecessary-type-assertion": "error", + "@typescript-eslint/no-unsafe-assignment": "off", + "@typescript-eslint/no-unsafe-call": "error", + "@typescript-eslint/no-unsafe-member-access": "error", + "@typescript-eslint/no-unsafe-return": "error", + "@typescript-eslint/no-unused-expressions": "error", + "@typescript-eslint/no-unused-vars": "warn", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/no-var-requires": "error", + "@typescript-eslint/prefer-as-const": "error", + "@typescript-eslint/prefer-for-of": "error", + "@typescript-eslint/prefer-function-type": "error", + "@typescript-eslint/prefer-namespace-keyword": "error", + "@typescript-eslint/prefer-regexp-exec": "error", + "@typescript-eslint/quotes": "off", + "@typescript-eslint/require-await": "error", + "@typescript-eslint/restrict-plus-operands": "error", + "@typescript-eslint/restrict-template-expressions": "error", + "@typescript-eslint/triple-slash-reference": [ + "error", + { + "path": "always", + "types": "prefer-import", + "lib": "always" + } + ], + "@typescript-eslint/unbound-method": "error", + "@typescript-eslint/unified-signatures": "error", + "arrow-parens": [ + "off", + "always" + ], + "brace-style": [ + "off", + "off" + ], + "comma-dangle": "off", + "complexity": "off", + "constructor-super": "error", + "curly": "off", + "dot-notation": "error", + "eqeqeq": [ + "error", + "smart" + ], + "guard-for-in": "error", + "id-blacklist": "off", + "id-match": "off", + "import/order": "off", + "indent": "off", + "jsdoc/check-alignment": "error", + "jsdoc/check-indentation": "off", + "jsdoc/newline-after-description": "error", + "max-classes-per-file": "off", + "max-len": "off", + "new-parens": "error", + "no-array-constructor": "off", + "no-bitwise": "error", + "no-caller": "error", + "no-cond-assign": "error", + "no-console": "warn", + "no-debugger": "error", + "no-empty": "off", + "no-empty-function": "off", + "no-eval": "error", + "no-extra-semi": "off", + "no-fallthrough": "off", + "no-implied-eval": "off", + "no-invalid-this": "off", + "no-new-wrappers": "error", + "no-shadow": "error", + "no-throw-literal": "error", + "no-trailing-spaces": "error", + "no-undef-init": "error", + "no-underscore-dangle": "off", + "no-unsafe-finally": "error", + "no-unused-expressions": "error", + "no-unused-labels": "error", + "no-unused-vars": "off", + "no-use-before-define": "off", + "no-var": "error", + "object-shorthand": "error", + "one-var": [ + "error", + "never" + ], + "prefer-arrow/prefer-arrow-functions": "off", + "prefer-const": "error", + "quotes": "off", + "radix": "error", + "require-await": "off", + "spaced-comment": [ + "error", + "always", + { + "markers": [ + "/" + ] + } + ], + "use-isnan": "error", + "valid-typeof": "off" + } }; diff --git a/spec/container-async.spec.ts b/spec/container-async.spec.ts index 656f0ab..3444a5b 100644 --- a/spec/container-async.spec.ts +++ b/spec/container-async.spec.ts @@ -687,8 +687,8 @@ describe('Asynchronous error handling', () => { expect(clone.get('const')).toBe(orig.get('const')); // Since we resolved B in orig, it's singleton state carried over to clone, so we should be able to release. - expect(c.b.b).toEqual("B"); + expect(c.b.b).toEqual('B'); clone.releaseSingletons(); - expect(c.b.b).toEqual("released"); + expect(c.b.b).toEqual('released'); }); }); diff --git a/spec/container-sync.spec.ts b/spec/container-sync.spec.ts index e60169f..4205e03 100644 --- a/spec/container-sync.spec.ts +++ b/spec/container-sync.spec.ts @@ -1,10 +1,10 @@ /* eslint-disable */ import 'jasmine'; -import "reflect-metadata"; +import 'reflect-metadata'; import {InjectionToken} from '../src'; // noinspection ES6PreferShortImport -import { Container } from '../src/container'; +import {Container} from '../src/container'; import {Injectable, PostConstruct, Release} from '../src/decorators'; let counter = 1; @@ -185,6 +185,7 @@ describe('Constants', () => { interface I { a: string; } + const token = new InjectionToken('implicit'); const container = new Container(); @@ -238,6 +239,7 @@ describe('PostConstruct execution', () => { public constructor() { this.i = 'PostConstruct'; } + public i: string; public a: string; @@ -269,6 +271,7 @@ describe('PostConstruct execution', () => { public constructor() { this.i = 'PostConstruct'; } + public i: string; public a: string; @@ -388,12 +391,13 @@ describe('Synchronous error handling', () => { expect(err.message).toBe('Unable to initialize A'); } }); - it("Success handler's failure should invoke ErrorHandler with constructed object", () => { + it('Success handler\'s failure should invoke ErrorHandler with constructed object', () => { @Injectable() class A { public constructor() { this.a = 'A'; } + public a: string; } diff --git a/spec/decorators.spec.ts b/spec/decorators.spec.ts index 95eff7b..fb31e06 100644 --- a/spec/decorators.spec.ts +++ b/spec/decorators.spec.ts @@ -1,11 +1,10 @@ /* eslint-disable */ import 'jasmine'; -import "reflect-metadata"; -import { POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS } from '../src/constants'; -import { Container } from '../src/container'; -import { Inject, Injectable, Optional, PostConstruct, _getInjectedIdAt } from '../src/decorators'; -import { InjectableId } from '../src/injector'; +import 'reflect-metadata'; +import {POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS} from '../src/constants'; +import {Container, InjectableId} from '../src'; +import {_getInjectedIdAt, Inject, Injectable, Optional, PostConstruct} from '../src/decorators'; describe('@Injectable', () => { it('Should generate proper metadata', () => { diff --git a/src/async-factory-provider.ts b/src/async-factory-provider.ts index 7fa851c..de0187d 100644 --- a/src/async-factory-provider.ts +++ b/src/async-factory-provider.ts @@ -1,7 +1,7 @@ -import { BindableProvider } from './bindable-provider'; -import { AsyncFactory } from './binder'; -import { InjectableId, Injector } from './injector'; -import { State } from './state'; +import {BindableProvider} from './bindable-provider'; +import {AsyncFactory} from './binder'; +import {InjectableId, Injector} from './injector'; +import {State} from './state'; /** * @inheritDoc diff --git a/src/bindable-provider.ts b/src/bindable-provider.ts index 8640971..66fea01 100644 --- a/src/bindable-provider.ts +++ b/src/bindable-provider.ts @@ -1,7 +1,7 @@ -import { AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory } from './binder'; -import { ClassConstructor, InjectableId, Injector } from './injector'; -import { Provider } from './provider'; -import { isErrorObj } from './utils'; +import {AsyncFactory, BindAs, OnErrorCallback, OnSuccessCallback, SyncFactory} from './binder'; +import {ClassConstructor, InjectableId, Injector} from './injector'; +import {Provider} from './provider'; +import {isErrorObj} from './utils'; /** * @inheritDoc diff --git a/src/binder.ts b/src/binder.ts index b418556..bf6b11f 100644 --- a/src/binder.ts +++ b/src/binder.ts @@ -1,4 +1,4 @@ -import { AbstractConstructor, ClassConstructor, InjectableId, Injector } from './injector'; +import {AbstractConstructor, ClassConstructor, InjectableId, Injector} from './injector'; /** * Type definition for functions that return a value. @@ -55,6 +55,7 @@ export type OnSuccessCallback = (value: T, injector: Injector, id: Injecta export interface BindErrHandler { onError(cb: OnErrorCallback): void; } + /** * An interface allowing binding of a post construction handler. * @@ -89,6 +90,7 @@ export interface Binder extends Injector { * The container will also invoke any `@PostConstruct` present on the class. */ bindClass(id: ClassConstructor, constructor?: ClassConstructor): BindAs>; + bindClass(id: string | symbol | AbstractConstructor, constructor: ClassConstructor): BindAs>; /** diff --git a/src/class-provider.ts b/src/class-provider.ts index 7bcb191..eb498c3 100644 --- a/src/class-provider.ts +++ b/src/class-provider.ts @@ -1,9 +1,9 @@ -import { BindableProvider } from './bindable-provider'; -import { POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS } from './constants'; -import { _getInjectedIdAt, _getOptionalDefaultAt } from './decorators'; -import { ClassConstructor, InjectableId, Injector } from './injector'; -import { State } from './state'; -import { isPromise } from './utils'; +import {BindableProvider} from './bindable-provider'; +import {POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_PARAMS} from './constants'; +import {_getInjectedIdAt, _getOptionalDefaultAt} from './decorators'; +import {ClassConstructor, InjectableId, Injector} from './injector'; +import {State} from './state'; +import {isPromise} from './utils'; /* * This is a bit of a hack, but it avoids a ton of alternative hacks. @@ -61,7 +61,8 @@ export class ClassBasedProvider extends BindableProvider { return this.successHandler(obj, this.injector, this.id, this.maker); }; - } else { + } + else { /* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */ // Check to see if there is a @PostConstruct annotation on a method of the class. let postConstruct: string = Reflect.getMetadata(POSTCONSTRUCT_SYNC_METADATA_KEY, obj.constructor); diff --git a/src/constant-provider.ts b/src/constant-provider.ts index 6333a35..8166ee7 100644 --- a/src/constant-provider.ts +++ b/src/constant-provider.ts @@ -1,5 +1,5 @@ -import { Provider } from './provider'; -import { State } from './state'; +import {Provider} from './provider'; +import {State} from './state'; /** * @inheritDoc diff --git a/src/container.ts b/src/container.ts index 5413f3a..457c9c9 100644 --- a/src/container.ts +++ b/src/container.ts @@ -1,14 +1,14 @@ -import { AsyncFactoryBasedProvider } from './async-factory-provider'; +import {AsyncFactoryBasedProvider} from './async-factory-provider'; import {BindableProvider} from './bindable-provider'; -import { AsyncFactory, BindAs, Binder, SyncFactory } from './binder'; -import { ClassBasedProvider } from './class-provider'; -import { ConstantProvider } from './constant-provider'; -import { INJECTABLE_METADATA_KEY } from './constants'; -import { AbstractConstructor, ClassConstructor, InjectableId, Injector } from './injector'; -import { Provider } from './provider'; -import { State } from './state'; -import { FactoryBasedProvider } from './sync-factory-provider'; -import { isPromise } from './utils'; +import {AsyncFactory, BindAs, Binder, SyncFactory} from './binder'; +import {ClassBasedProvider} from './class-provider'; +import {ConstantProvider} from './constant-provider'; +import {INJECTABLE_METADATA_KEY} from './constants'; +import {AbstractConstructor, ClassConstructor, InjectableId, Injector} from './injector'; +import {Provider} from './provider'; +import {State} from './state'; +import {FactoryBasedProvider} from './sync-factory-provider'; +import {isPromise} from './utils'; /** * Helper class to ensure we can distinguish between Error instances legitimately returned from Providers, and Errors thrown by Providers. @@ -30,6 +30,7 @@ export class Container implements Binder { */ public constructor(protected parent?: Injector) { } + protected providers = new Map, Provider>(); /** @@ -179,7 +180,7 @@ export class Container implements Binder { }); }); }; - if (parentRecursion && typeof (this.parent as Binder)?.resolveSingletons === "function") { + if (parentRecursion && typeof (this.parent as Binder)?.resolveSingletons === 'function') { const pb: Binder = this.parent as Binder; return pb.resolveSingletons(asyncOnly, parentRecursion).then(() => { return makePromiseToResolve().then(() => this); @@ -246,10 +247,10 @@ export class Container implements Binder { * The way to avoid this last effect is to @see resolveSingletons */ clone(clazz?: ClassConstructor): Container { - if (! clazz) + if (!clazz) clazz = Container; const retVal = new clazz(this.parent); - this.providers.forEach((v,k) => { + this.providers.forEach((v, k) => { if (v instanceof BindableProvider) { v = Object.assign(Object.create(Object.getPrototypeOf(v)), v); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access diff --git a/src/decorators.ts b/src/decorators.ts index 83e63d0..c090159 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -2,8 +2,8 @@ /** * These decorators all apply the information they collect (whether class, method, or parameter data) as tagged metadata on the class's constructor */ -import {INJECTABLE_METADATA_KEY, INJECT_METADATA_KEY, OPTIONAL_METADATA_KEY, POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_RETURN, RELEASE_METADATA_KEY} from './constants'; -import { InjectableId } from './injector'; +import {INJECT_METADATA_KEY, INJECTABLE_METADATA_KEY, OPTIONAL_METADATA_KEY, POSTCONSTRUCT_ASYNC_METADATA_KEY, POSTCONSTRUCT_SYNC_METADATA_KEY, REFLECT_RETURN, RELEASE_METADATA_KEY} from './constants'; +import {InjectableId} from './injector'; // Help user locate misapplied decorators. function targetHint(target: Function) { @@ -113,7 +113,7 @@ export function Optional(alt?: any): ParameterDecorator { // eslint-disable-li */ return function (target: Function, parameterName: string | symbol, parameterIndex: number): void { const paramKey = validateSingleConstructorParam('Optional', target, parameterIndex); - Reflect.defineMetadata(OPTIONAL_METADATA_KEY, { value: alt }, target, paramKey); + Reflect.defineMetadata(OPTIONAL_METADATA_KEY, {value: alt}, target, paramKey); }; } @@ -152,7 +152,8 @@ export function PostConstruct(): MethodDecorator { const rt = Reflect.getMetadata(REFLECT_RETURN, target, methodName); if (typeof rt === 'function') { Reflect.defineMetadata(POSTCONSTRUCT_ASYNC_METADATA_KEY, methodName, target.constructor); - } else { + } + else { Reflect.defineMetadata(POSTCONSTRUCT_SYNC_METADATA_KEY, methodName, target.constructor); } }; diff --git a/src/index.ts b/src/index.ts index 2ec58d9..d2d5378 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { Binder } from './binder'; -export { Container } from './container'; -export { Inject, Injectable, Optional, PostConstruct } from './decorators'; -export { ClassConstructor, InjectableId, InjectionToken, Injector } from './injector'; +export {Binder} from './binder'; +export {Container} from './container'; +export {Inject, Injectable, Optional, PostConstruct} from './decorators'; +export {ClassConstructor, InjectableId, InjectionToken, Injector} from './injector'; diff --git a/src/injector.ts b/src/injector.ts index 34fb6f2..3eb7c7a 100644 --- a/src/injector.ts +++ b/src/injector.ts @@ -11,10 +11,11 @@ export type ClassConstructor = new (...args: any[]) => T; * Allow for implicit typing of constants and interfaces. * Inspired by Angular and some colleges at work. */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars export class InjectionToken { constructor(private id: string | symbol) { } + toString(): string { return this.id.toString(); } diff --git a/src/provider.ts b/src/provider.ts index 2df97fa..d2dd91c 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -1,5 +1,5 @@ -import { State } from './state'; -import { InvokeReleaseMethod } from './utils'; +import {State} from './state'; +import {InvokeReleaseMethod} from './utils'; /** diff --git a/src/state.ts b/src/state.ts index ea307d4..80e0df6 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,4 +1,4 @@ -import { isPromise } from "./utils"; +import {isPromise} from './utils'; /** * Internal class that allows us to track the state of a promise (chain). diff --git a/src/sync-factory-provider.ts b/src/sync-factory-provider.ts index 8f46f41..d40225c 100644 --- a/src/sync-factory-provider.ts +++ b/src/sync-factory-provider.ts @@ -1,7 +1,7 @@ -import { BindableProvider } from './bindable-provider'; -import { SyncFactory } from './binder'; -import { InjectableId, Injector } from './injector'; -import { State } from './state'; +import {BindableProvider} from './bindable-provider'; +import {SyncFactory} from './binder'; +import {InjectableId, Injector} from './injector'; +import {State} from './state'; /** * @inheritDoc diff --git a/src/types/reflect.d.ts b/src/types/reflect.d.ts index ab36346..a5d5178 100644 --- a/src/types/reflect.d.ts +++ b/src/types/reflect.d.ts @@ -1 +1 @@ -import "reflect-metadata/standalone"; +import 'reflect-metadata/standalone'; diff --git a/src/utils.ts b/src/utils.ts index 98eb448..6a58a25 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,25 +6,25 @@ import {RELEASE_METADATA_KEY} from './constants'; */ export function isErrorObj(err: any): err is Error { if (!err) - return false; + return false; - if (err instanceof Error) - return true; + if (err instanceof Error) + return true; - return err && typeof err.message === 'string' && typeof err.stack === 'string'; + return err && typeof err.message === 'string' && typeof err.stack === 'string'; } /** * Returns true if the specified value is "thenable" (aka a Promise). */ export function isPromise(value: any): value is Promise { - if (!value) - return false; + if (!value) + return false; - if (value instanceof Promise) - return true; + if (value instanceof Promise) + return true; - return value && typeof value.then === 'function'; + return value && typeof value.then === 'function'; } /** @@ -32,7 +32,7 @@ export function isPromise(value: any): value is Promise { * This is primarily an internal method as you probably know the exact method, and should invoke it yourself. * async-injection uses this helper to allow Singletons to clean up any non-garbage-collectable resources they may have allocated. */ -export function InvokeReleaseMethod(obj: T) : boolean { +export function InvokeReleaseMethod(obj: T): boolean { const releaseMethod: string = Reflect.getMetadata(RELEASE_METADATA_KEY, obj.constructor); /* eslint-disable @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access */ if (releaseMethod && obj.constructor.prototype[releaseMethod] && typeof obj.constructor.prototype[releaseMethod] === 'function') {