Last active
July 31, 2023 12:20
-
-
Save AkinAguda/155f0801036004340c6aff02f93cb1ba to your computer and use it in GitHub Desktop.
Force React component to expect certain props if another is defined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface CommonData { | |
someRandomData: string; | |
} | |
type DataOne = { | |
someDataOneValue: string; | |
}; | |
type DataTwo = { | |
someDataTwoValue: string; | |
}; | |
type OneOrTwo = | |
| (DataTwo & Partial<Record<keyof DataOne, never>>) | |
| (DataOne & Partial<Record<keyof DataTwo, never>>); | |
type ComponentProps = OneOrTwo & CommonData; | |
const Component: React.FC<ComponentProps> = () => { | |
return <></>; | |
}; | |
const Test: React.FC = () => { | |
return <Component someRandomData="" someDataOneValue="" />; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment