question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular component is not compiling with “--prod” option: Object is of type “unknown”

See original GitHub issue

Affected 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:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
usarskyycommented, Jan 10, 2020

@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.

0reactions
angular-automatic-lock-bot[bot]commented, Feb 28, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

prod build gives referring to a type without a variable error
ng build --configuration=production --base-href /my-app/ --prod ... Unknown compiler option 'files' launching ./node_modules/.bin/ng-xi18n.
Read more >
Angular Update Guide
All CLI commands now use two dashes for flags (eg ng build --prod --source-map ) to be POSIX ... Warnings about unknown elements...
Read more >
CodeWarrior Development Studio for Microcontrollers V10.x ...
Batch Mode (Compiler Window not Open). ... 7.2.3.78 -Prod: Specify Project File at Startup ... 25.1.245 C1838: Unknown object-size: sizeof (incomplete type) ...
Read more >
rollup.js
unknownGlobalSideEffects Assume unknown globals do not throw ... rollup --config rollup.config.dev.js rollup --config rollup.config.prod.js ...
Read more >
Angular 15: New features and breaking changes - devmio
export function authInterceptor(request: HttpRequest<unknown>, ... “environment.ts” and “environment.prod.ts” are also no longer supplied as the standard.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found