I'm trying to understand how this code works, because it seems like it should not, but it does work.
Is this some TypeScript magic I'm not understanding? React magic? How does this work if the cases are not strings, but imported values which appear as undefined
?
Code source
import DialogTitle, { DialogTitleProps } from "./Title";import DialogDescription, { DialogDescriptionProps } from "./Description";import DialogButton, { DialogButtonProps } from "./Button";// .... React.Children.forEach(children, (child) => { if (typeof child === "object" && child !== null && "type" in child) { switch (child.type) { case DialogTitle: // DialogTitle is undefined in the debugger when hovered titleChildrens.push(child as TitleElement); return; case DialogDescription: // DialogDescription is undefined in the debugger when hovered descriptionChildrens.push(child as DescriptionElement); return; case DialogButton: // DialogButton is undefined in the debugger when hovered if (Platform.OS === "ios" && buttonChildrens.length > 0) { buttonChildrens.push(<View style={[ verticalButtons ? styles.buttonSeparatorVertical : styles.buttonSeparatorHorizontal, buttonSeparatorStyle, ]} /> ); } buttonChildrens.push(child as ButtonElement); return; } } otherChildrens.push(child); });