Add support for navigation stack screen title type narrowing
C
Charles Johnson
The
title
and header
properties for StackNavigationOptions
allow for arbitrary strings as the title prop but I wanted to pass a translation key for the title and localise the text within the header
component. I generate a union type of translation key strings based on the translations I have and wanted to restrict the title
of navigation screens to be this union type.I was able to patch @react-navigation/stack and @react-navigation/elements to satisfying my needs for react-navigation v6 but now I have to repatch react-navigation v7 and also manually edit files in the
lib
directory, not just the source code, so that typescript accesses the modified types for my application.Here are the source code changes that I would apply for v7: https://github.com/Charles-Johnson/react-navigation/commit/ffa5bddb718122122008220020af4ee2ee10bca3
Is this something that react-navigation could support in the future or is there a better way to handle my use case?
Thank you for your considerations.