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

React Navigation custom route params and typescript

$
0
0

I have an Error screen that needs to know the error number and a description to display the error and I can't figure out how to tell TS which types are my Error screen custom params. I'm calling my Error screen this way.

  navigation.dispatch(    StackActions.replace('Error', {      statusCode: 400,      description: 'Error description',    }),  );

This is my Error screen component. TS complains in route.params

export default function ErrorScreen({ route, navigation }: RootStackScreenProps<'Error'>) {  const { statusCode, description } = route.params; <-- TS error here  // @ts-ignore  const { setClientURL } = appState(({ setClientURL }) => ({    setClientURL,  }));

TS2339: Property 'description' does not exist on type 'Readonly {key: string; index: number; routeNames: string[]; history?: unknown[]| undefined; routes: NavigationRoute []; type: string; stale: false;}>> | undefined>'.

How can I tell TS that for my Error screen route.params can have statusCode and description primitives?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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