diff --git a/packages/core/src/di/r3_injector.ts b/packages/core/src/di/r3_injector.ts index 2f16c70f6d..c618d5d5b3 100644 --- a/packages/core/src/di/r3_injector.ts +++ b/packages/core/src/di/r3_injector.ts @@ -435,7 +435,7 @@ function deepForEach(input: (T | any[])[], fn: (value: T) => void): void { } function isValueProvider(value: SingleProvider): value is ValueProvider { - return value && typeof value == 'object' && USE_VALUE in value; + return value !== null && typeof value == 'object' && USE_VALUE in value; } function isExistingProvider(value: SingleProvider): value is ExistingProvider { @@ -456,7 +456,7 @@ function hasDeps(value: ClassProvider | ConstructorProvider | StaticClassProvide } function hasOnDestroy(value: any): value is OnDestroy { - return typeof value === 'object' && value != null && (value as OnDestroy).ngOnDestroy && + return value !== null && typeof value === 'object' && typeof(value as OnDestroy).ngOnDestroy === 'function'; } diff --git a/packages/core/src/render3/interfaces/injector.ts b/packages/core/src/render3/interfaces/injector.ts index f93fd5f18a..9b8a6695e8 100644 --- a/packages/core/src/render3/interfaces/injector.ts +++ b/packages/core/src/render3/interfaces/injector.ts @@ -248,7 +248,7 @@ export class NodeInjectorFactory { const FactoryPrototype = NodeInjectorFactory.prototype; export function isFactory(obj: any): obj is NodeInjectorFactory { // See: https://jsperf.com/instanceof-vs-getprototypeof - return obj != null && typeof obj == 'object' && Object.getPrototypeOf(obj) == FactoryPrototype; + return obj !== null && typeof obj == 'object' && Object.getPrototypeOf(obj) == FactoryPrototype; } // Note: This hack is necessary so we don't erroneously get a circular dependency diff --git a/packages/core/src/view/ng_module.ts b/packages/core/src/view/ng_module.ts index cfd5462e92..a09f79943d 100644 --- a/packages/core/src/view/ng_module.ts +++ b/packages/core/src/view/ng_module.ts @@ -158,7 +158,7 @@ function _createProviderInstance(ngModule: NgModuleData, providerDef: NgModulePr // avoided if possible. The sequence of checks here determines whether ngOnDestroy needs to be // checked. It might not if the `injectable` isn't an object or if NodeFlags.OnDestroy is already // set (ngOnDestroy was detected statically). - if (injectable !== UNDEFINED_VALUE && injectable != null && typeof injectable === 'object' && + if (injectable !== UNDEFINED_VALUE && injectable !== null && typeof injectable === 'object' && !(providerDef.flags & NodeFlags.OnDestroy) && typeof injectable.ngOnDestroy === 'function') { providerDef.flags |= NodeFlags.OnDestroy; }