diff --git a/routes/quiz/_components/Quiz.tsx b/routes/quiz/_components/Quiz.tsx index 0d76012..3a47f4b 100644 --- a/routes/quiz/_components/Quiz.tsx +++ b/routes/quiz/_components/Quiz.tsx @@ -1,4 +1,5 @@ import { Delayed } from "../../../components/Delayed.tsx"; +import type { TextChoiceQuestion } from "../_trivia_api_types.ts"; import { QuizAnswer } from "./QuizAnswer.tsx"; import { QuizScore } from "./QuizScore.tsx"; @@ -25,7 +26,7 @@ async function Question() { ); if (response.ok) { - const questions = await response.json(); + const questions = await response.json() as TextChoiceQuestion[]; const { id, question: { text }, correctAnswer, incorrectAnswers } = questions[0]; diff --git a/routes/quiz/_trivia_api_types.ts b/routes/quiz/_trivia_api_types.ts new file mode 100644 index 0000000..ae69561 --- /dev/null +++ b/routes/quiz/_trivia_api_types.ts @@ -0,0 +1,14 @@ +export interface TextChoiceQuestion { + type: "text_choice"; + id: string; + question: { + text: string; + }; + correctAnswer: string; + incorrectAnswers: string[]; + category: string; + tags: string[]; + difficulty: string; + regions: string[]; + isNiche: boolean; +} diff --git a/routes/quiz/answer/:id/:answer.tsx b/routes/quiz/answer/:id/:answer.tsx index 008ff3c..4f9c7c7 100644 --- a/routes/quiz/answer/:id/:answer.tsx +++ b/routes/quiz/answer/:id/:answer.tsx @@ -3,6 +3,7 @@ import { QuizAnswer } from "../../_components/QuizAnswer.tsx"; import { notFound } from "@http/fns/response/not_found"; import { getQuizSession, updateQuizScore } from "../../_lib/session.ts"; import { QuizScore } from "../../_components/QuizScore.tsx"; +import type { TextChoiceQuestion } from "../../_trivia_api_types.ts"; export default handleFragment( async function AnswerResult({ req, match }) { @@ -24,7 +25,7 @@ export default handleFragment( "Content-Type": "application/json", }, }, - )).json(); + )).json() as TextChoiceQuestion; const correct = answer === question.correctAnswer;