property decorators break at runtime with ES2015 and circular deps
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/coreIs this a regression?
NoDescription
Using the `@Input()` property decorator (or any other property decorators I imagine) targetting ES2015 with a circular dependency on a type will cause a `Uncaught ReferenceError` at runtime.π¬ Minimal Reproduction
git clone https://github.com/filipesilva/istiti-circular-deps-es2015
cd istiti-circular-deps-es2015
ng serve
# src/app/autocomplete.directive.ts contains the problematic decorator and circular dep
π₯ Exception or Error
main.js:9545 Uncaught ReferenceError: Cannot access 'AutocompleteAbstract' before initialization
at Module.AutocompleteAbstract (main.js:9545)
at Module../src/app/autocomplete.directive.ts (main.js:9580)
at __webpack_require__ (runtime.js:79)
at Module../src/app/autocomplete.abstract.ts (main.js:9546)
at __webpack_require__ (runtime.js:79)
at Module../src/app/parent.component.ts (main.js:9605)
at __webpack_require__ (runtime.js:79)
at Module../src/app/app.module.ts (main.js:9507)
at __webpack_require__ (runtime.js:79)
at Module../src/main.ts (main.js:9666)
π Your Environment
Angular Version:
Angular CLI: 8.0.0-beta.16
Node: 10.10.0
OS: win32 x64
Angular: 8.0.0-beta.13
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.800.0-beta.16
@angular-devkit/build-angular 0.800.0-beta.16
@angular-devkit/build-optimizer 0.800.0-beta.16
@angular-devkit/build-webpack 0.800.0-beta.16
@angular-devkit/core 8.0.0-beta.16
@angular-devkit/schematics 8.0.0-beta.16
@angular/cli 8.0.0-beta.16
@ngtools/webpack 8.0.0-beta.16
@schematics/angular 8.0.0-beta.16
@schematics/update 0.800.0-beta.16
rxjs 6.4.0
typescript 3.4.4
webpack 4.30.0
Anything else relevant?
cc @istiti
This is similar to https://github.com/angular/angular/issues/30106. In this case it is not a constructor parameter type, but rather a class property type.
A class property by itself doesnβt need metadata with a type reference:
// transpiled src/app/autocomplete.directive.ts without Input() decorator
import * as tslib_1 from "tslib";
import { Directive } from '@angular/core';
let AutocompleteDirective = class AutocompleteDirective {
constructor() { }
};
// this is used in autocomplete.abstract.ts
AutocompleteDirective.EMPTYLIST_ELEMENT = "_EMPTYLIST_";
AutocompleteDirective = tslib_1.__decorate([
Directive({
selector: '[appAutocomplete]'
}),
tslib_1.__metadata("design:paramtypes", [])
], AutocompleteDirective);
export { AutocompleteDirective };
But when the property is decorated, the metadata will contain a reference to the type:
// transpiled src/app/autocomplete.directive.ts with Input() decorator
import * as tslib_1 from "tslib";
import { Directive, Input } from '@angular/core';
import { AutocompleteAbstract } from './autocomplete.abstract';
let AutocompleteDirective = class AutocompleteDirective {
constructor() { }
};
// this is used in autocomplete.abstract.ts
AutocompleteDirective.EMPTYLIST_ELEMENT = "_EMPTYLIST_";
tslib_1.__decorate([
Input('appAutocomplete'),
tslib_1.__metadata("design:type", AutocompleteAbstract)
], AutocompleteDirective.prototype, "autocomplete", void 0);
AutocompleteDirective = tslib_1.__decorate([
Directive({
selector: '[appAutocomplete]'
}),
tslib_1.__metadata("design:paramtypes", [])
], AutocompleteDirective);
export { AutocompleteDirective };
In ES5 there are no class
declarations, so TS instead uses a var
. One important different between var
and class/let/const
is that the latter are all subject to the Temporal Dead Zone.
Without the Input()
decorator this isnβt a problem because there is no circular dependency on the type.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Cannot access 'MyComponent' before initialization in Angular 10
Property decorators break at runtime with ES2015 and circular deps on GitHub angular/angular Β· ES2015 + emitDecoratorMetadata causes CannotΒ ...
Read more >typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScriptΒ ...
Read more >How to fix nasty circular dependency issues once and for all in ...
In the many projects I have maintained so far, sooner or later I always run into the same issue: circular module dependencies.
Read more >class-transformer - npm
Class objects are instances of classes with own defined constructor, properties and methods. Usually you define them via class notation. So,Β ...
Read more >@babel/runtime | Yarn - Package Manager
Fast, reliable, and secure dependency management. ... babel's modular runtime helpers ... :boom: [Breaking Change]; :eyeglasses: [Spec Compliance]Β ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
still not fixed
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.