react-navigation / react-navigation/react-navigation.github.io
Inconsistent TypeScript behavior with optional arguments in useNavigation
オープン
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue の useNavigation の例で TypeScript エラーを再現し、次に @react-navigation/native の useNavigation のエントリポイントと型定義を調べます。ナビゲーションの型付けを正しく保ったまま、@ts-ignore コメントを必要とせずにオプションの string 引数が受け入れられれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, react-native, typescript
- 領域
- api, mobile-dev
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100