Inconsistent TypeScript behavior with optional arguments in useNavigation
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react, react-native, typescript
- 领域
- api, mobile-dev
调研方向
首先复现 issue 中 useNavigation 示例的 TypeScript 错误,然后检查 @react-navigation/native 中 useNavigation 的入口点及其类型定义。完成的标准是:可接受可选的 string 参数,而无需使用 @ts-ignore 注释,同时导航类型保持正确。
由索引模型根据 Issue 内容生成。
描述
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)
}
- 主要语言
- JavaScript
- 星标
- 324
- 派生
- 2k
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
react-navigation/react-navigation.github.io 的其他 Issue
-
难度 1/5 1 小时以内 新手友好度 94/100
react-navigation/react-navigation.github.io#1516 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 1/5 1 小时以内 新手友好度 72/100
-
难度 1/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 72/100
查看 react-navigation/react-navigation.github.io 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
palladius/rails8-app-on-gcp#145 ·
-
难度 2/5 1-3 小时 新手友好度 65/100
dotenvx/dotenv-vscode#139 ·
-
test-change-proposal
难度 2/5 1-3 小时 新手友好度 65/100
web-platform-tests/interop#1455 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
corsairdev/corsair#1764 ·
-
难度 2/5 1-3 小时 新手友好度 75/100