【发布时间】:2019-09-16 10:10:27
【问题描述】:
我试图用 Typescript 实现 react native。在尝试访问 react-navigation library 时。它抛出打字稿错误。
类型'Readonly & Readonly'。
我的组件.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>
)
}
}
导出默认首页;
请告诉我如何解决此错误。另外请指点我使用接口实现类型。
【问题讨论】:
标签: reactjs typescript react-native