TypeError: Cannot read property 'onDestroy' of undefined -- paths to resolution
See original GitHub issueI don’t want to just submit a patch here for the problem as it would assume developer intent. Let’s see what the problem is.
I’ve traced the bug in one scenario. If you decorate a regular class (not a component) with @UntilDestroyed() (which used to execute silently even if it perhaps should not have ?), instantiate it directly (myVar = new MyClass()) then this call in decorateDeclarable(type, options)
def.onDestroy = decorateNgOnDestroy(def.onDestroy, options);
triggers the error.
If you just want to avoid the error (and keep the buggy assumptions of decorated classes) then the error can be suppressed by bracketing the code:
if (def !== undefined) { def.onDestroy = decorateNgOnDestroy(def.onDestroy, options); markAsDecorated(def); }
and perhaps adding a warning. However the more constructive behaviour might be to synthesize a way to convert that decorated class into something that behaves like a component with its expected onDestroy lifecycle stage.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
I love your libraries by the way. Very well thought-out.
Glad you’ve resolved the issue!