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

How to properly use unions with route params for react-navigation-v6 in Typescript

$
0
0

When using react-navigation-v6 with Typescript, I've been encountering ts-lint errors such as this one: Property 'variable' does not exist on type 'Readonly<{ variable1: string; } | { variable2: string; }>'.

Property 'variable' does not exist on type 'Readonly<{ variable1: string; } | { variable2: string; }>

I assume it has much to do with my lack of understanding of Typescript and unions, but how would I improve the code below to remove any ts-lint errors?

import { StackScreenProps } from '@react-navigation/stack'import React from 'react'type TestScreenParamList = {  TestScreen: { randomString: string }  TestScreen2: { randomString2: string }}type TestScreenStackProps = StackScreenProps<TestScreenParamList, 'TestScreen' | 'TestScreen2'>const TestScreen = ({ route, navigation }: TestScreenStackProps) => {  console.log(route.params.randomString)  return <></>}

Thanks in advance


Viewing all articles
Browse latest Browse all 6290

Trending Articles



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