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

Object is possibly 'undefined' when apply for number

$
0
0

I'm trying to make custom view component base on device size, but typescript complain about number, it said Object is possibly 'undefined', here is the code

export interface ViewContainerProps {  style?: ViewStyle | ViewStyle[];  children?: React.ReactNode;  percentWidth?: number;  percentHeight?: number;}export const ViewContainer = (props: ViewContainerProps) => {  const {style, children, percentHeight,percentWidth} = props;  return (<View style={[style, {height: onePercentHeight * percentHeight}]}> // no, this number is undefined!?      {children}</View>  );};

What happen, how to fix this, thank you guys a lots


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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