Mordechai Tzarfati
08/03/2022, 1:13 PMProperty 'answers' does not exist on type '(Questions & { answers: Answers[]; }) | never[]'.
Property 'answers' does not exist on type 'never[]'
and i used this type:
type QuestionWithAnswers = Prisma.QuestionsGetPayload<{
include: { answers: true }
}>
my code:
const question = await this.prisma.questions.findUnique({
where: {
id: questionId
},
include: {
answers: true
}
});
any idea what im doing wrong?Nurul
08/03/2022, 1:46 PMMichael Jay
08/03/2022, 2:27 PMnull instead of never[], then it would be if(!question) <handle what happens when the ID was bad.
So returning an array of ANY sort is very weird behavior indeed for findUnique to be doing, and must have something to do with your model declaration. So I'll be interested to see it too.
Since (I hope) you're expecting that question should be your QuestionWithAnswers type (and thus NOT an array), you could probably get TS to stop complaining if you ran something like:
if (Array.isArray(question)) throw new Error("You're NEVER going to believe this...") , where the important thing is that you know your method will stop execution if question is any type of array, including never[]Michael Jay
08/03/2022, 2:33 PMlet alphabetArray;
["a", "b", "c"].forEach(letter => alphabetArray.push(letter));
Where you declare a variable and then try to treat it as an array.Mordechai Tzarfati
08/03/2022, 2:42 PM