Presented below are the two interfaces:
export interface IQuestion {
type: 'single' | 'sort'
prompt: string;
options: {
id: string,
text: string
}[]
}
export type ICurrentQuestion = {
correctAnswerId: string | string[],
question: IQuestion,
extraData?: IResultsAnswerData
}
I aim to ensure that correctAnswerId
is of type string[]
when the question type is sort
. I prefer not to relocate the type to the top level because the content within the question is directly sent to the client. This would result in duplication of the type at both levels. While my research suggests my desired approach may not be feasible, I am struggling to determine the most effective way to maintain type safety here.
A big thank you in advance to all the brilliant minds out there!:)