Skip to content

Instantly share code, notes, and snippets.

@mystikraz
Created July 9, 2023 07:13
Show Gist options
  • Select an option

  • Save mystikraz/f3f46dbf68fc4e2b460e07fcffaf19bd to your computer and use it in GitHub Desktop.

Select an option

Save mystikraz/f3f46dbf68fc4e2b460e07fcffaf19bd to your computer and use it in GitHub Desktop.
props optional compulsory
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)
}
if(props.gender==='female'){
console.log(props.weight)}
return <div>child>/div>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment