I use the following type as property for my component:
type MapProps = {
standalone: true
} | {
standalone: false
inContextOf: Nullable<Artifact | ExcavationSite>
fieldSetter: UseFormSetValue<FieldValue<any>>
}
Further down, the following checks are performed:
if ((props.standalone || !props.standalone && !props.inContextOf) || props.inContextOf && !IsEntityArtifact(props.inContextOf))
return;
if (props.inContextOf?.Latitude == 0.0 && props.inContextOf.Longitude == 0.0)
return;
const newPoint = {
type: "Feature",
geometry: {
type: "Point",
coordinates: [props.inContextOf!.Longitude, props.inContextOf!.Latitude]
}
};
Everything is working as expected with this implementation, however as soon as i move those checks to a function like this
const CheckReturnScenarios = (): boolean => {
if ((props.standalone || !props.standalone && !props.inContextOf) || props.inContextOf && !IsEntityArtifact(props.inContextOf))
return true;
if (props.inContextOf?.Latitude == 0.0 && props.inContextOf.Longitude == 0.0)
return true;
return false;
};
and I use it like this
if (CheckReturnScenarios())
return;
const newPoint = {
type: "Feature",
geometry: {
type: "Point",
coordinates: [props.inContextOf!.Longitude, props.inContextOf!.Latitude]
}
};
I do get the following error: TS2339: Property inContextOf does not exist on type MapProps Property inContextOf does not exist on type { standalone: true; }
I’m wondering why it’s suddenly no longer possible for TypeScript to determine that the properties being accessed must exist here, because otherwise the check performed above would abort the function.
Would be nice if someone could shed some light on this.
Thank you!