Last active
July 17, 2023 06:45
-
-
Save turbod/5cd347d2d9511624a84cf13b7e01bd9e to your computer and use it in GitHub Desktop.
Conditional Types
This file contains 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 Props = { | |
name: string | |
} & (MaleProps | FemaleProps) | |
type MaleProps = { | |
gender: 'male' | |
salary: number | |
} | |
type FemaleProps = { | |
gender: 'female' | |
weight: number | |
} | |
const Child = (props: Props) { | |
if (props.gender === 'male') { | |
console.log(props.salary} | |
else if (props.gender === 'female') { | |
console.log(props.gender === 'male') | |
} | |
return <h1>child</h1> | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment