Created
April 8, 2024 17:47
-
-
Save thepuskar/1a9f8d88ca61bf3f91fdb803af49946d to your computer and use it in GitHub Desktop.
TypeScript conditional types based on property value
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
type IProps = { | |
children: React.ReactNode; | |
asChild?: boolean; | |
} & (IModalProp | IRedirectProp); | |
interface IModalProp { | |
mode: "modal"; | |
} | |
interface IRedirectProp { | |
mode: "redirect"; | |
redirectUrl: string; | |
} | |
// Modal usage: | |
<MyComponent asChild mode="modal">Some content</MyComponent> | |
// Redirection usage: | |
<MyComponent mode="redirect" redirectUrl="/some-page">Rerouting...</MyComponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment