Skip to content
This repository has been archived by the owner on Dec 3, 2022. It is now read-only.

I can't define NavigationParams types with useNavigation #49

Closed
Aure77 opened this issue Nov 14, 2019 · 1 comment · May be fixed by #50
Closed

I can't define NavigationParams types with useNavigation #49

Aure77 opened this issue Nov 14, 2019 · 1 comment · May be fixed by #50

Comments

@Aure77
Copy link

Aure77 commented Nov 14, 2019

There is a way to define navigation params typing on useNavigation with typescript ?

  const navigation = useNavigation<{ params: { title: string } }>();
  const title = navigation.getParam("title"); // title is inferred as "any" not "string"...

This is not working useNavigation because of this (P default value/type) :

export interface NavigationScreenProp<S, P = NavigationParams> {
  state: S & { params?: P };
...

there is no access to optional second type on NavigationScreenProp...

@slorber
Copy link
Member

slorber commented Nov 18, 2019

Hi,

This looks a bit similar to #42 so I'm closing.

For now the best solution is probably something like useNavigation() as NavigationStackProp<MyParams>

I don't have much time to work on this currently but PRs are welcome

@slorber slorber closed this as completed Nov 18, 2019
Aure77 pushed a commit to Aure77/hooks that referenced this issue Nov 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants