0

I am gettings errors everywhere after I migrated to angular 12 from angular 8. By the way I did not get any error when migrating from 8 to 9, neither from 9 to 10, nor from 10 to 11.

Here is an example of error I get:

export interface HistoriqueStatutModel {
  userId: string;
  date: Date;
  statutCible: string;
  commentaire?: string;
  montantFacture?: number;
}

export interface CommentaireModel {
  message: string;
  date: Date;
  createdBy: string;
}

--- 

public listeStatut: Array<HistoriqueStatutModel | CommentaireModel>;

---

 <li *ngFor="let statut of listeStatut;">
    {{statut.message}}
 </li>

I get this error:

error TS2339: Property 'message' does not exist on type 'HistoriqueStatutModel | CommentaireModel'.
  Property 'message' does not exist on type 'HistoriqueStatutModel'.
 {{statut.message}}

Any idea ?

Amir Choubani
  • 829
  • 2
  • 14
  • 28

1 Answers1

1

Angular 12 was the first version that had template type checking set to strict by default, that's why you're only now seeing these errors.

You can turn this off in your TypeScript configuration file by setting the strictTemplates flag to false.

Of course, it would be better to perform proper type checking in your code instead.

Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156