-2

I'm new to Angular and I try to declare a new object type or a simple string variable but I get an error

this_is_variable:string;
recipe : Recipe;

the errors:

Property 'recipe' has no initializer and is not definitely assigned in the constructor.

Property 'this_is_variable' has no initializer and is not definitely assigned in the constructor.

In the above example Recipe is a class which I have import it

export class Recipe{
public name:string;
public description : string;
public imagePath: string;
constructor(name:string="none", desc:string="none" , imagePath:string="none"){
    this.name= name;
    this.description=desc;
    this.imagePath= imagePath;


}

}
HamzaDevXX
  • 154
  • 1
  • 10

1 Answers1

2

The reported error is from typescript compiler. Set the property strictPropertyInitialization to false in tsconfig.json file of Angular app solution to avoid this compiler error.

{
  "compilerOptions": {
    // ... rest
    "strictPropertyInitialization": false
  }
}
Wazeed
  • 1,230
  • 1
  • 8
  • 9