Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

How to type Partial State object in React Navigation?

$
0
0

New to TS and having trouble finding the right typing. I am trying to pass in a partial state object to a helper function I wrote to reset the navigation state. The partial state object looks like this:

const state = {  routes: [{ name: 'Home' }, { name: 'Profile', params: {uid: 1} }],};

I am not sure what is the correct way to type it. My helper function looks something like this:

const reset = (  name: string,  params: any = {},  key: any = 0,  navState?: PartialState<Route>; // <- How to type this? ) = () => {   ...}

I tried looking in the types file and found PartialState or PartialRoute that seems something I can use, but I'm not sure how to use it. Any help would be appreciated! Have included the typings from the types file below for reference:

export declare type PartialRoute<R extends Route<string>> = Omit<R, 'key'> & {key?: string;state?: PartialState<NavigationState>;};export declare type PartialState<State extends NavigationState> = Partial<Omit<State, 'stale' | 'routes'>> & Readonly<{    stale?: true;    routes: PartialRoute<Route<State['routeNames'][number]>>[];}>;

Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>