@trivia-api/models
v1.39.0
Published
Models for The Trivia API.
Downloads
64
Readme
Trivia API Models
Typescript models and guards for types used in The Trivia API.
Usage
Install the models with npm install @trivia-api/models
, and use within Typescript files:
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",
};