I'm encountering an error that I can't quite figure out:
Type '"New Choice"' is not assignable to type '"Yes" | "No"'.ts(2322)
test.ts(17, 14): The expected type comes from property 'text' which is declared here on type '{ text:
"Yes"; } | { text: "No"; }'
While attempting to define multiple parameters with objects, I'm running into some issues.
This is the code snippet in question:
export class HomeComponent implements OnInit {
survey:{
name:"My Quick Survey",
questionnaires:[{
question:"Ready for a quick survey?",
multi:true,
choices:[
{text:"Yes"},
{text:"No"}
]
}]
}
results:{
success:"",
error:""
}
addchoice(i) {
this.survey.questionnaires[i].choices.push({text:"New Choice"})
// Error occurs at this line
}
removechoice(i,j) {
this.survey.questionnaires[i].choices.splice(j,1)
}
addquestion() {
this.survey.questionnaires.push({
question:"Next question?", // Error occurs here
multi:true,
choices:[
{text:"Choice1"}, // Error occurs here
{text:"Choice2"} // Error occurs here
]
})
}
}
Any ideas on how I can fix these errors?