首页 > 解决方案 > 打字稿错误 - 不要将函数用作类型

问题描述

我已经开始TypeScript在我的React-Native项目中使用

我的 linter 不喜欢函数作为一种类型,我该如何重构我的 hoc 以通过我的 linter?

应用导航器:

const withHeader = (
    screen: Function,
    routeName: string,
    Header,
): StackNavigator =>
    createStackNavigator(
        {
            [routeName]: {
                screen,
                navigationOptions: ({routeName, props}) => ({
                    header: props => <Header {...props} />,
                }),
            },
        },
        {
            initialRoute: 'Home',
            cardStyle: {
                backgroundColor: 'transparent',
                opacity: 1,
            },
            transitionConfig: () => ({
                containerStyle: {
                    backgroundColor: 'transparent',
                },
            }),
        },
    );

我的打包程序还给我一个相同文件的错误:

error: bundling failed: Error: Unable to resolve module `./navigation/AppNavigator` from `C:\Users\Matt\sites\IAapp\App.tsx`: The module `./navigation/AppNavigator` could not be found from `C:\Users\Matt\sites\IAapp\App.tsx`. Indeed, none of these files exist:

标签: typescriptreact-native

解决方案


推荐阅读