【发布时间】:2019-09-08 07:21:30
【问题描述】:
我有以下两段代码:
CustomHeader.tsx
import { View, StyleSheet, Button } from 'react-native';
import { NavigationScreenProps } from 'react-navigation';
import Icon from 'react-native-vector-icons/Ionicons';
export const CustomHeader = ({ navigation }: NavigationScreenProps) => (
<View style={[styles.container]}>
<Icon
name="md-menu"
size={32}
color="black"
style={{ marginLeft: 10 }}
onPress={() => navigation.openDrawer()}
/>
</View>
);
const styles = StyleSheet.create({
container: {
borderBottomWidth: 2,
height: 70,
paddingTop: 20,
},
});
DetailScreen.tsx
import React from 'react';
import { Text, View, Button, Alert } from 'react-native';
import { NavigationScreenProps } from "react-navigation";
import { CustomHeader } from '../components/Header';
export class ChangeAccountDetailScreen extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<CustomHeader navigation={this.props.navigation} />
<Text style={{ fontSize: 20 }}>Profile Screen</Text>
</View>
);
}
}
在detailscreen中我收到以下错误:
类型'Readonly & Readonly'。
我搜索了这个问题,我知道它有一些事实,即我没有在我的 CustomHeader 中声明类型。但是我不知道如何解决这个问题。我对打字稿有点陌生。有人可以向我解释如何解决这种类型的问题吗?
【问题讨论】:
-
哪一行导致该错误?顺便说一句,
type Props = NavigationScreenProps;Props 类型,你的意思是extends React.Component<Props>? -
您好,对不起,我忘了删除那行。我更新了代码..我得到错误的行是
<CustomHeader navigation={this.props.navigation} />,特别是this.pros.navigation -
您尝试过我建议的修复方法吗?
-
嘿,您建议的修复方法解决了它!非常感谢。
标签: typescript react-native react-navigation