Issue
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;
}
}
Solution
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
}
}
Answered By - Wazeed
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.