I am designing a unique header:
const customHeader = ({ navigation, route, options, back }: NativeStackHeaderProps): React.ReactNode => {
const buttons: HeaderRightButtons = route.params?.rightButtons || []
return (...)
}
An error is displayed in Typescript:
The property 'rightButtons' does not exist on the type 'object'
This property should contain an Array of "buttons":
type HeaderRightButtons = Array<{ icon: any, action: () => void }>
I attempted to create an extended type:
export type NativeStackHeaderPropsCustomRight =
(NativeStackHeaderProps & {
route: RouteProp<{params?: { rightButtons: HeaderRightButtons }}, 'params'>
}) | NativeStackHeaderProps
However, this did not resolve the issue.
The property "rightButtons" does not exist in the type "object | (object & Readonly<{ rightButtons: HeaderRightButtons; }>)". The "rightButtons" property does not exist in the "object" type.
When excluding | NativeStackHeaderProps
, an error appears in the screen declaration:
<Stack.Screen ... options={{
header: customHeader,
title: strings.titleEpochs
}} />
The type "({ navigation, route, options, back }: NativeStackHeaderPropsCustomRight) => React.ReactNode" cannot be assigned to type "(props: NativeStackHeaderProps)
How can I define the correct type?
Is there a more appropriate way to pass an object as properties to a custom header?