Noob TRPC quesiton regarding response JSON
I am struggling with parsing some JSON my TRPC API is responding, and hoping to receive some guidance.
I have a TRPC API which calls a table created in Prisma , as follows:
As you can see, it is being parsed as a
Now, my problem is I want to access the properties of fetchedQuiz. specifcially, the quizData property. I know this JSON being returned has the properties
Property 'questions' does not exist on type 'string | number | boolean | JsonObject | JsonArray'
This is obviously because it can't parse the properties of the quizData Json from Prisma.
How would you suggest I go about ensuring this can be parsed?
Some things I have tried are:
Defining my own types for the response which matches the JSON, and then trying to cast the useQuery, as follows:
But this doesn't work, as
Any suggestions are helpful.
I have a TRPC API which calls a table created in Prisma , as follows:
As you can see, it is being parsed as a
quiz type, this is defined in prisma as follows:Now, my problem is I want to access the properties of fetchedQuiz. specifcially, the quizData property. I know this JSON being returned has the properties
questions, "correctAns", "selectedAnswers" and "allAnswers". However typescript complains when I try to access these properties, because the JSON isnt defined in Prisma, giving me the error: Property 'questions' does not exist on type 'string | number | boolean | JsonObject | JsonArray'
This is obviously because it can't parse the properties of the quizData Json from Prisma.
How would you suggest I go about ensuring this can be parsed?
Some things I have tried are:
Defining my own types for the response which matches the JSON, and then trying to cast the useQuery, as follows:
But this doesn't work, as
fetchedQuiz is still of type quiz.Any suggestions are helpful.
