react-navigation / react-navigation/react-navigation.github.io
Inconsistent TypeScript behavior with optional arguments in useNavigation
未关闭
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 324
- 派生
- 2k
- PR 合并指标
- 30 天内没有已合并 PR
描述
When using the useNavigation hook from @react-navigation/native in TypeScript, optional arguments are not being correctly inferred and produce a type error.
Expected Behavior:
Optional arguments should be correctly inferred and not produce a type error.
Actual Behavior:
Optional arguments produce a type error, requiring the use of the // @ts-ignore comment to suppress the error.
Steps to Reproduce:
- Use the useNavigation hook with an optional argument.
- Attempt to pass a string value as the optional argument.
- Observe the type error.
import { useNavigation } from '@react-navigation/native';
const navigation = useNavigation();
const navigate = (screenName?: string) => {
// Argument of type 'string' is not assignable to parameter of type 'never'
navigation.navigate(screenName)
// Workaround with // @ts-ignore
// @ts-ignore
navigation.navigate(screenName)
}
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 issue 中 useNavigation 示例的 TypeScript 错误,然后检查 @react-navigation/native 中 useNavigation 的入口点及其类型定义。完成的标准是:可接受可选的 string 参数,而无需使用 @ts-ignore 注释,同时导航类型保持正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react, react-native, typescript
- 领域
- api, mobile-dev
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100