Closed1

Zodを使って共通の定義を使い回す方法

KanonKanon

https://zod.dev/?id=merge

const CommonQuestionFields = z.object({
  title: z.string(),
  questionFormat: z.string().optional(),
  statement: z.string(),
  commentary: z.string(),
});

const MultiSelectableQuestionSchema = CommonQuestionFields.merge(
  z.object({
    select1: MultiSelectableAnswerSchema,
    select2: MultiSelectableAnswerSchema,
    select3: MultiSelectableWrongSchema,
    select4: MultiSelectableWrongSchema,
  })
);

const FillInTheBlankQuestionSchema = CommonQuestionFields.merge(
  z.object({
    answer: z.string(),
  })
);
このスクラップは2024/04/28にクローズされました