how do i prevent non-nullable types in arguments #22375
Closed
Description
so we have the following convenience function:
export function asDefinedOr<T, D>(value: T | undefined, defaultValue: D): T | D {
return value !== undefined ? value : defaultValue;
}
we would like to prevent the following from happening
declare var x : number;
asDefinedOr(x, 0); // <-- problem, unnecessary call, because x cannot be undefined
so we would like to make only T | undefined
types allowed as aguments but not just T
is there a way to do it using conditional types?