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

Property doesn't exist on type 'object' in React Native with TypeScript

$
0
0

I'm very new to React Native and TypeScript so forgive me if the the question is trivial.

In my application I have a screen to which I'm navigating with React-Navigation I'm also passing a callback function through the navigation.

navigation.navigate('BluredSuccess', {blurredSuccessCallback})

I show the BlurredScreen for 2 secs and then I close using navigation.pop and call the callback function like this:

import { NavigationScreenProp } from 'react-navigation';import { Route } from '@react-navigation/native';interface Props {    navigation?: NavigationScreenProp,    route: Route<any>}const LoginOtpSuccess : React.FC<Props> = ({navigation, route: {params}}) => {    React.useEffect(() => { setTimeout(() => {        navigation.pop()        params.blurredSuccessCallback() // here I see an error.    }, 2000) })    return (<View style={styles.container}><BlurView                style={styles.absolute}                blurType="light"                blurAmount={40}                reducedTransparencyFallbackColor="white"            /><Image source={require('../../../assets/otp_success.png')} style={{width:90, height:90}}></Image></View>    )}

Now the code works in general but I keep seeing an error on my callback method stating:

Property 'blurredSuccessCallback' does not exist on type 'object'. 

I also see Object is possibly 'undefined'. on the params variable.

How can I fix this error? What should be the correct types of navigation and route in my Props interface I don't think using any is the correct way.


Viewing all articles
Browse latest Browse all 6215

Trending Articles



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