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 }, [])