I want to check if some data has the correct type before passing it as props to a component. I tried this way but it gives an error Teacher' only refers to a type, but is being used as a value here
:
const renderSearchResult = () => {
switch (true) {
case searchFilter.groups:
return <GroupInfos groupData={typeof searchResult === Group ? searchResult : null} />
case searchFilter.teachers:
return <AddTeacher teacher={typeof searchResult === Teacher ? searchResult : null} mode={MODAL_MODE.update} />
default:
return <AddStudentModal student={typeof searchResult === Student ? searchResult : null} mode={MODAL_MODE.update} />
}
}