Created
March 11, 2019 16:47
-
-
Save ratbeard/1d283015cbed237718ac98698bf6c787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/questions/46641380/exhaustive-map-over-a-union-of-typed-objects | |
// https://www.typescriptlang.org/docs/handbook/advanced-types.html | |
export function getInteractiveSection2({ question }: { | |
question: Question; | |
}) { | |
switch(question.type) { | |
case 'multiple-choice': | |
return <ChoicesSection {...buildItChoice({ question })} />; | |
case 'fill-in-the-blank': | |
return <FillInTheBlankView {...buildFillInTheBlankInteraction({ question })} />; | |
case 'matching': | |
return <MatchingSection {...buildMatchingInteraction({ question })} />; | |
// case 'ranking': | |
// return <RankingInteractionView {...buildRankingInteraction({ question })} />; | |
default: | |
return assertUnreachable(question); | |
} | |
} | |
export function getInteractiveSection3({ question }: { | |
question: Question; | |
}) { | |
if (question.type === 'multiple-choice') { | |
return <ChoicesSection {...buildItChoice({ question })} />; | |
} else if (question.type === 'fill-in-the-blank') { | |
return <FillInTheBlankView {...buildFillInTheBlankInteraction({ question })} />; | |
} else if (question.type === 'matching') { | |
return <MatchingSection {...buildMatchingInteraction({ question })} />; | |
} else if (question.type === 'ranking') { | |
return <RankingInteractionView {...buildRankingInteraction({ question })} />; | |
} else { | |
return assertUnreachable(question); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ideally i'd want a switchType(question, { 'multiple-choice': q => , 'fill-in': q => ... })
but have wasted 2 much thyme on that. e.g.: