-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
TypeScript Version: 3.4.0-dev.20190202
Search Terms: Conditional Resolution, Optionals
Code
interface RangeProps {
range?: false;
onApply?: (value: Date) => void;
}
interface SingleProps {
range: true;
onApply?: (value: [Date, Date]) => void;
}
type CalendarProps = RangeProps | SingleProps;
function apply (props: CalendarProps) {
if (props.onApply) {
if (props.range) {
// Should work as already inside props.onApply check.
props.onApply([new Date(), new Date()]);
} else {
// Should work as already inside props.onApply check.
props.onApply(new Date());
}
}
}
Expected behavior:
Above code should not throw error.
Actual behavior:
Error at lines after comment: Cannot invoke an object which is possibly 'undefined'.
Related Issues:
Tried my best, sorry but could not find any
Please also change/suggest the title of issue if it does not reflect on the error.
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed