我决定将流程集成到我的项目中,无法解决一些类型错误。我进行了很多搜索,但找不到以下值的类型。
例如
我在下面共享我的代码,但遇到错误。预先感谢
/*** @flow*/
import { Component } from 'react';
import * as React from 'react';
import {
Text,
View,
Image,
TouchableOpacity,
AppState,
Alert,
TextInput
} from 'react-native';
import { Auth } from 'aws-amplify';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import PhoneInput from 'react-native-phone-input';
import {
StackActions,
NavigationActions,
NavigationScreenProps
} from 'react-navigation';
import { ProgressDialog } from 'react-native-simple-dialogs';
import { styles } from './Styles';
import { FloatingLabelInput, CTAButton } from 'Components';
import { strings } from '../../../utility/locales/i18n';
import AppUtil from 'Library/Utils/AppUtil';
import * as DateUtil from 'Library/Utils/DateUtil';
import { R } from 'Resources';
import { inject, observer } from 'mobx-react/native';
import { Query } from 'react-apollo';
import { USER_TYPE, USER_ONBOARDING_STEP } from 'Library/Constants';
import * as UserQueries from 'AppSyncQueries/UserQueries';
import LocalNotification from '../../../Components/LocalNotification/LocalNotification';
import PushNotificationController from '../../../Components/LocalNotification/PushNotificationController';
import moment from 'moment';
type Props = NavigationScreenProps & {};
type passwordRef = {|
current: any | null
|};
type State = {
userName: string,
password: string,
loading: boolean,
valid: boolean,
shouldLoadProfile: boolean
};
@inject('loginUserStore', 'userAccountStore', 'measurementUnitStore')
@observer
export class Login extends Component<Props, State> {
static navigationOptions = {
title: strings('login.title'),
header: null
};
constructor(props) {
super(props);
this.passwordRef = React.createRef();
this.state = {
userName: '',
password: '',
loading: false,
valid: false,
shouldLoadProfile: false,
startProgramDate: this.props.userAccountStore.programStartDate
};
this.updateInfo = this.updateInfo.bind(this);
this.localNotification = new LocalNotification();
this.scheduleLocalNotification = this.scheduleLocalNotification.bind(this);
}
onChangeText(key: string, value: string) {
this.setState({ password: value });
}
updateInfo() {
this.setState({
valid: this.phone.isValidNumber()
});
}
gotoDashboard() {
this.props.navigation.dispatch(AppUtil.resetAction('Dashboard', {}));
}
completeNewPassword(user: any) {
this.props.navigation.navigate('SetPassword', { user: user });
}
startPasswordReset() {
const title = strings('login.password_reset_required_title');
const message = strings('login.password_reset_required_message');
Alert.alert(title, message, [
{
text: 'Ok',
onPress: () => {
this.props.navigation.navigate('ResetPassword', {
userName: this.phone.getValue()
});
}
}
]);
}
render() {
return (
<KeyboardAwareScrollView
style={{ backgroundColor: R.Colors.COLOR_APP_BACKGROUND }}
scrollEnabled
extraScrollHeight={50}
enableResetScrollCoords
resetScrollToCoords={{ x: 0, y: 0 }}
>
<View style={styles.container}>
{AppUtil.renderProgressBar(
this.state.loading,
strings('common_message.please_wait')
)}
<Image source={R.Images.logo} style={styles.appLogo} />
<View style={styles.loginContainer}>
<TextInput
style={{ height: 35, color: '#929CA5', fontSize: 14 }}
editable={false}
selectTextOnFocus={false}
value='Phone Number'
/>
<View style={styles.userName}>
<PhoneInput
onPressFlag={this.onPressFlag}
ref={ref => {
this.phone = ref;
}}
/>
</View>
<View style={{ marginTop: 15, marginLeft: 1 }}>
<FloatingLabelInput
style={styles.textField}
secureTextEntry
label='Password'
returnKeyType='done'
ref={this.passwordRef}
value={this.state.password}
onChangeText={text => this.setState({ password: text })}
/>
</View>
<View style={styles.forgotPasswordBtnContainer}>
<TouchableOpacity onPress={this.gotoForgotPassword.bind(this)}>
<Text style={styles.forgotPasswordBtn}>Forgot Password?</Text>
</TouchableOpacity>
</View>
<CTAButton
label='LOGIN'
isEnabled={true}
onClick={this.loginClick.bind(this)}
style={{ marginTop: 30 }}
/>
</View>
<PushNotificationController />
</View>
</KeyboardAwareScrollView>
);
}
}
如果您检查构造函数的代码,会发现许多变量和引用都被使用。我仍然想描述每个错误,这将有助于理解
道具缺少类型注释。(对于构造器道具)
无法将React.createRef()分配给this.passwordRef,因为Login [1]中缺少属性passwordRef
无法将this.updateInfo.bind(...)分配给this.updateInfo,因为属性updateInfo是不可写的。
无法为this.localNotification分配新的LocalNotification(),因为Login [1]中缺少属性localNotification