react-navigation / react-navigation/react-navigation.github.io
Inconsistent TypeScript behavior with optional arguments in useNavigation
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- JavaScript
- Sterne
- 324
- Forks
- 2k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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)
}
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, den TypeScript-Fehler im useNavigation-Beispiel aus dem Issue zu reproduzieren, und untersuche anschließend den Einstiegspunkt von useNavigation und dessen Typdefinitionen in @react-navigation/native. Die Aufgabe ist abgeschlossen, wenn ein optionales String-Argument akzeptiert wird, ohne einen @ts-ignore-Kommentar zu erfordern, während die Typisierung der Navigation korrekt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- react, react-native, typescript
- Bereich
- api, mobile-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100