```Property 'answers' does not exist on type '(Que...
# orm-help
m
Copy code
Property 'answers' does not exist on type '(Questions & { answers: Answers[]; }) | never[]'.
  Property 'answers' does not exist on type 'never[]'
and i used this type:
Copy code
type QuestionWithAnswers = Prisma.QuestionsGetPayload<{
    include: { answers: true }
}>
my code:
Copy code
const question = await this.prisma.questions.findUnique({
            where: {
                id: questionId
            },
            include: {
                answers: true
            }
        });
any idea what im doing wrong?
✅ 1
n
Hey 👋 Could you share your schema file or just the questions and answers model?
m
@Mordechai Tzarfati - It's weird that TS thinks that your return could be a never[]. On my findUniques, the option is either some sort of success return unioned with null. With strict mode enabled, this keeps me honest - I always make sure that the return was actually what I wanted. In your case, if your type was unioned with
null
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[]
PS. I don't think this is going on here right now, but the most common way I've seen never[] to pop up is:
Copy code
let alphabetArray;
["a", "b", "c"].forEach(letter => alphabetArray.push(letter));
Where you declare a variable and then try to treat it as an array.
m
thanks for the help guys!