I was trying to implement react native with Typescript. while trying to access react-navigation library . Its throwing typescript errors.
Property 'navigation' does not exist on type 'Readonly<{}> & Readonly<{ children?: ReactNode; }>'.
My component.tsx
import React, { Component } from "react";
import { View, Text, TouchableHighlight, Alert } from "react-native";
import {
NavigationParams,
NavigationScreenProp,
NavigationState,
} from 'react-navigation';
class FirstPage extends Component {
public static navigationOptions = {
title: 'Test Screen',
};
constructor(props: any) {
super(props);
}
_call = (firstName:string,lastName:string) => {
Alert.alert(
'Title',
`${firstName} ${lastName}`,
[
{text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{cancelable: false},
);
// Alert( `$(firstname) $(lastName)`)
}
_nav=()=>
{
this.props.navigation.navigate('second');
}
render() {
return (
<View>
<Text>Hello First Page</Text>
<TouchableHighlight onPress={()=>this._call('hello','user')} >
<Text>Types Button</Text>
</TouchableHighlight>
<TouchableHighlight onPress={()=>this._nav} >
<Text>Types Button</Text>
</TouchableHighlight>
</View>
)
}
}
export default FirstPage;
Please let me know how to resolve this errors. In addition please point me towards implementing types using interfaces.