Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How does this switch statement work? The case values appear to be undefined in the debugger

$
0
0

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);  });

enter image description here

enter image description here


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>