Skip to content

Types for Typescript users of react-quiz-component (.d.ts) #273

@d3vAdv3ntur3s

Description

@d3vAdv3ntur3s

Nice job with the library, I was trialing the component, doesn't quite fit for my use case, but I thought it might be useful to have some Types to assist for Typescript users. Quickly put this together whilst I was trying out the component, hopefully helpful to you if not onlookers.

File: react-quiz-component.d.ts

    declare module 'react-quiz-component' {
      import { ReactElement } from 'react';
      
      type QuestionType = "text" | "photo"
      
      type AnswerSelectionType = "single" | "multiple"
  
      type Question = {
          question: string
          questionType: QuestionType
          answers: string[]
          correctAnswer: string
          answerSelectionType: AnswerSelectionType
          messageForCorrectAnswer?: string
          messageForIncorrectAnswer?: string
          explanation?: string
          point?: string
          segment?: string
      }
  
      type QuizStructure = {
          quizTitle: string
          questions: question[]
      }
  
      type QuizProps = {
          quiz: QuizStructure;
          disableSynopsis?: boolean;
          shuffleAnswer?: boolean;
          shuffle?: boolean;
          showDefaultResult?: boolean;
          showInstantFeedback?: boolean;
          continueTillCorrect?: boolean;
          timer?: number;
          allowPauseTimer?: boolean
      }
  
      const Quiz: (props: QuizProps) => ReactElement;
      export default Quiz;
  }
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions