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

Why typescript occurs compile error with using the surrounded constant condition?

$
0
0

I'm always curious about when the union-type condition handling in Typescript with React-native is used, If I used const with surrounding conditions, Typescript does not detect the inner condition of const. It must exist within the same scope for it to work.

Why it occurs compile error?

example

  import {isNull} from 'lodash';  ...,  const scrollViewRef = useRef<ScrollView | null>(null)  const onPressFooter = useCallback(() => {    if (isNull(scrollViewRef)) return; --> b line show compile error    if (scrollViewRef === null) return; --> b line not occurs error     scrollViewRef.current.scrollTo({y :0, animated : true}) // -> b  }, [])

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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