Angular component is not compiling with “--prod” option: Object is of type “unknown”
See original GitHub issueAffected Package
Not sure
Is this a regression?
Not sure
Description
This is a copy-paste from https://stackoverflow.com/questions/59667441/angular-component-is-not-compiling-with-prod-option-object-is-of-type-unknow
I am trying to compile my Angular application for production (“–prod” option) but I get lots of weird errors like:
blah.component.html(15,11): Object is of type ‘unknown’
Template code that produces these errors is following:
<tbody>
<tr *ngFor="let item of items$ | async">
<td>{{item.name}}</td>
<td>{{item.code}}</td>
</tr>
</tbody>
items$ variable defined as following:
public item$: Observable<ListItem[]>;
What I don’t understand is why I am receiving these error messages as almost same code on my private laptop compiles as expected!
I would be appreciated for any help!
UPDATE 1:
Another error, that I haven’t noticed earlier, points to ngFor statement and says:
blah.component.html(14,11): Type ‘ListItem[] | null’ is not assignable to type ‘ListItem[] | Iterable | undefined’.
Why Angular compiler thinks that items$ property can be either array, or null? It is explicitely defined as Observable<ListItem[]>.
When I changed my template as shown below, these error messages dissapeared:
<ng-container *ngIf="items$ | async as tmp">
<tr *ngFor="let item of tmp">
<td>{{item.name}}</td>
...
🔬 Minimal Reproduction
Just create a simple component with ngFor="let item of items$ | async"
🔥 Exception or Error
blah.component.html(14,11): Type ‘ListItem[] | null’ is not assignable to type ‘ListItem[] | Iterable | undefined’.
blah.component.html(15,11): Object is of type ‘unknown’
🌍 Your Environment
Angular Version:
- Angular CLI: 8.3.22
- Angular: 8.2.14
- Node: 11.12.0
- typescript: 3.5.3
Ivy and AOT are enabled.
Anything else relevant?
Similar code compiles as expected on another laptop with same version of Angular packages!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (2 by maintainers)

Top Related StackOverflow Question
@atscott not sure if this is reproducable. As I wrote before, similar code is compiling fine on another laptop. But I will try to create you an example project with same issues.
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.