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