I am getting an error when I give
export class UserComponent implements OnInit {
user:User;
constructor(){
}
ngOnInit(){
this.user = {
firstName : "test",
lastName : "test",
age : 40,
address: {
street : "Test",
city : "test",
state: "test"
}
}
}
}
I am getting this error:
Property 'user' has no initializer and is not definitely assigned in the constructor.
user is inherited from User.ts and User.ts contains the below code:
export interface User {
firstName:string,
lastName:string,
age?:number,
address?:{
street?: string,
city?:string,
state?:string
}
}
Adding ?
to user is showing error in some other file:
There is another folder named users...That is the main one...Now when I add ? here, it shows me this error.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…