UNPKG

@trivia-api/models

Version:

Models for The Trivia API.

35 lines (28 loc) 1.04 kB
# Trivia API Models Typescript models and guards for types used in [The Trivia API](https://the-trivia-api.com). ## Usage Install the models with `npm install @trivia-api/models`, and use within Typescript files: ```ts import { type Question } from "@trivia-api/models"; // The Typescript compiler will complain because there is no `incorrectAnswers` property const invalidQuestion: Question = { question: "What is the capital of France?", correctAnswer: "Paris", category: "Geography", tags: ["france", "capital_cities", "europe"], type: "Multiple Choice", difficulty: "easy", id: "abcde-fg", }; // The compiler will be happy because this is a valid instance of Question - all required properties are present. const validQuestion: Question = { question: "What is the capital of France?", correctAnswer: "Paris", incorrectAnswers: ["Lyon", "Marseilles", "Bordeaux"], category: "Geography", tags: ["france", "capital_cities", "europe"], type: "Multiple Choice", difficulty: "easy", id: "abcde-fg", }; ```