- Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
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?
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code