@trivia-api/models
TypeScript icon, indicating that this package has built-in type declarations

1.36.0 • Public • Published

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",
};

Package Sidebar

Install

npm i @trivia-api/models

Weekly Downloads

3

Version

1.36.0

License

ISC

Unpacked Size

395 kB

Total Files

234

Last publish

Collaborators

  • willfry