I want to set the return type of the function to be a certain type when the argument is true
function getProfile({isPrivate: boolean}): privateProfile | publicProfile {
if(isPrivate){
// fetches private profile and returns it
...
return fetchedPrivateProfile;
} else {
// fetches a public profile and returns it
...
return fetchedPublicProfile;
}
}
so when I specify the function with isPrivate set to true the editor knows that the return type is going to be privateProfile
const definitelyAPrivateProfile = getProfile({isPrivate:true});
// ^ definitelyAPrivateProfile: privateProfile
