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

Typescript ESLint, is it possible null check in global function and it pass ESLint

$
0
0
  const isNotNullNumber = (e: number | undefined) => {    if (e !== null && e !== undefined && e !== 0) {      return true;    }    return false;  };  //pass eslint  if (promotionBadgeData?.discountPercent) {    icon1 = <Text>{`${promotionBadgeData?.discountPercent}%\nOff`}</Text>;  }  //pass eslint  if (    promotionBadgeData?.discountPercent !== null &&    promotionBadgeData?.discountPercent !== undefined &&    promotionBadgeData?.discountPercent !== 0  ) {    icon1 = <Text>{`${promotionBadgeData?.discountPercent}%\nOff`}</Text>;  }  //fail eslint  if (isNotNullNumber(promotionBadgeData?.discountPercent)) {    icon1 = <Text>{`${promotionBadgeData?.discountPercent}%\nOff`}</Text>;  }

in this case, use the global function to null check and it will show

ESLint: Invalid type "number | undefined" of template literal expression.(@typescript-eslint/restrict-template-expressions)

so, is it possible use the global function to null check and pass the ESLint?

screen cap


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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