interface Name {
name: string;
}
interface LastName {
lastName: number;
}
<Component
name="Ivan"
lastName="" // error lastName is not presented on type Name
/>
<Component
name="Ivan" // error name is not presented on type LastName
lastName="Fenia"
family={['Ivan', 'Anya']}
/>
interface Name {
name: string;
}
interface LastName {
lastName: string;
family: string[];
}
function Component(props: Name): React.ReactElement;
function Component(props: LastName): React.ReactElement;
function Component(props: Name | LastName): React.ReactElement {
if ('family' in props) {
return <b>{props.lastName}</b>
} else {
return <b>{props.name}</b>
}
}