问题的详细定义
type QuestionSerializer =
| ChoiceQuestionSerializer
| TrueOrFalseQuestionSerializer;
type QuestionWithoutAnswerSerializer = Omit<
QuestionSerializer,
"answer" | "analysis"
>;
type QuestionWithStudentAnswerSerializer =
| ChoiceQuestionWithStudentAnswer
| TrueOrFalseQuestionWithStudentAnswer;
interface Question {
id: number; // 题目id
kind: "CHOICE" | "TRUE_FALSE";
stem: string; // 题干
}
interface ChoiceQuestionSerializer extends Question {
kind: "CHOICE";
options: {
[key: string]: string;
};
answer: string; // 答案 [与 options 的 key 一致]
analysis?: string; // 解析
}
interface ChoiceQuestionWithStudentAnswer extends ChoiceQuestionSerializer {
studentAnswer: string;
pass: boolean; // 是否正确
}
interface TrueOrFalseQuestionSerializer extends Question {
kind: "TRUE_FALSE";
answer: boolean; // 答案
analysis?: string; // 解析
}
interface TrueOrFalseQuestionWithStudentAnswer
extends TrueOrFalseQuestionSerializer {
studentAnswer: boolean;
pass: boolean; // 是否正确
}