首页 > 解决方案 > 如何使用带有 Typescript 的 expo AppLoading 组件?

问题描述

我正在尝试将基于 expo 的 react 本机应用程序重写为 TypeScript,并且 AppLoading 组件会生成一些我不知道如何处理 TypeScript 样式的错误。

编码:

    if (!this.state.isLoadingComplete && !this.props.skipLoadingScreen) {
        return (
            <AppLoading
                startAsync={this.loadResourcesAsync}
                onError={this.handleLoadingError}
                onFinish={this.handleFinishLoading}
            />
        );
    } else {
        return (
            <View style={Styles.container}>
                {Platform.OS === 'ios' && <StatusBar barStyle="default" />}
                <AppNavigator />
            </View>
        );
    }



    public loadResourcesAsync = async (): Promise<any> => {
        return Promise.all([
            Asset.loadAsync([
                require('./assets/images/bankid.png'),
            ]),
            Font.loadAsync({
                // This is the font that we are using for our tab bar
                ...Icon.Feather.font,
                // We include SpaceMono because we use it in HomeScreen.js. Feel free
                // to remove this if you are not using it in your app
                'scala-sans-regular': require('./assets/fonts/ScalaSans-Regular.ttf'),
                'scala-sans-bold': require('./assets/fonts/ScalaSans-Bold.ttf'),
            }),
        ])

    };

    private handleLoadingError = error => {
        // In this case, you might want to report the error to your error
        // reporting service, for example Sentry
        logError("_handleLoadingError", {
            error: error
        });
        console.warn(error);
    };

    private handleFinishLoading = () => {
        this.setState({ isLoadingComplete: true });
    };

这是打字稿编译器给出的错误,遗憾的是我不知道它要我做什么

启动异步错误 onError 错误 完成错误

标签: typescriptreact-nativeexpo

解决方案


推荐阅读