refactor(core): correct typing checks when registering destroy hooks (#44087)

Making the typing filtering more explicit allows typescript to properly recognize the presence of the
`prototype` property on the provider within the `registerDestroyHooksIfSupported` method.

PR Close #44087
This commit is contained in:
Joey Perrott
2021-11-05 12:22:49 -07:00
committed by Andrew Scott
parent e0ae557aee
commit 401b5bf2af
+2 -2
View File
@@ -8,7 +8,7 @@
import {resolveForwardRef} from '../di/forward_ref';
import {ClassProvider, Provider} from '../di/interface/provider';
import {ClassProvider, Provider, TypeProvider} from '../di/interface/provider';
import {isClassProvider, isTypeProvider, providerToFactory} from '../di/r3_injector';
import {assertDefined} from '../util/assert';
@@ -192,7 +192,7 @@ function registerDestroyHooksIfSupported(
indexInFactory?: number) {
const providerIsTypeProvider = isTypeProvider(provider);
if (providerIsTypeProvider || isClassProvider(provider)) {
const prototype = ((provider as ClassProvider).useClass || provider).prototype;
const prototype = ((provider as ClassProvider).useClass || provider as TypeProvider).prototype;
const ngOnDestroy = prototype.ngOnDestroy;
if (ngOnDestroy) {
const hooks = tView.destroyHooks || (tView.destroyHooks = []);