Reputation: 194
I'm getting the following Typescript errors in my code
I'm getting these parameters from a previous screen. As in the example of the react nativigation documentation.
https://reactnavigation.org/docs/params/
interface PixChargeAmountProps {
route?: string;
}
const Amount: React.FC<PixChargeAmountProps> = ({ route }) => {
const { trackOriginFlow } = route.params;
}
console.log(route) ->
"params": {"trackOriginFlow": "ACTIVITIES_SCREEN_BUTTON"}, "path": undefined}
I get the following errors from route.params
route = Possibly the object is 'null'
params = Property 'params' does not exist in type 'string'
Upvotes: 0
Views: 103
Reputation: 2020
If you're planning to use route
as const { trackOriginFlow } = route.params;
and are saying that it cannot be null
, then your interface definition is incorrect.
It's probably more something along the lines of:
interface PixChargeAmountProps {
route: {
params: {
trackOriginFlow: string
}
}
}
However, I'd recommend reading the typescript guide, instead of trying to assemble this type yourself. See: Type checking with TypeScript
Upvotes: 1