Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent TypeScript behavior with optional arguments in useNavigation #1232

Open
ThePlatinum opened this issue Apr 12, 2023 · 0 comments

Comments

@ThePlatinum
Copy link

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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant