You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Navigation报错:No overload matches this call 求助

React Native Navigation 类型不匹配报错解决

报错信息

"message": "No overload matches this call.\n  Overload 1 of 2, '(...args: never): void', gave the following error.\n    Argument of type 'string' is not assignable to parameter of type 'never'.\n  Overload 2 of 2, '(options: never): void', gave the following error.\n    Argument of type 'string' is not assignable to parameter of type 'never'."

问题原因

调用useNavigation()时未指定正确的导航类型,导致TypeScript无法识别navigate方法的合法参数,将参数类型推断为never,与传入的'Signup'字符串类型冲突。

解决方案

修改HomeScreen.tsx的导航类型声明

给useNavigation()添加泛型约束,指定为基于RootStackParamList的栈导航属性类型:

import React from 'react';
import { View, StyleSheet, Text, Pressable } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { useQuery, gql } from '@apollo/client';
import { RootStackParamList, StackNavigationProp } from '../navigation/types';

export default function HomeScreen() {
  // 指定导航类型为RootStackParamList对应的栈导航属性
  const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();

  return (
    <View style={styles.container}>
      <Pressable 
        onPress={() => {
          console.warn('navigate'); 
          navigation.navigate('Signup');
        }} 
      >
        <Text>New here? Sign up</Text>
      </Pressable>   
    </View>
  );
}

补充说明

  • 若需要更精确的类型约束(限制当前页面仅能导航到特定路由),可指定当前页面的路由名称:
    const navigation = useNavigation<StackNavigationProp<RootStackParamList, 'Home'>>();
    
  • 你的types.tsx中已正确定义包含Signup的RootStackParamList,这部分无需修改。
  • 原代码中存在重复导入(Text、View)和多余语法符号(末尾的);),建议一并修正以避免潜在问题。

内容的提问来源于stack exchange,提问作者pelotador.1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 04:05:14