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; }>'.
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