I've recently started the process of converting all my code to support strictNullChecks. I have a specific requirement for a function that I need to implement:
function defaultValue<TUnionNull>(value: TUnionNull, default: TWithoutNull): TWithoutNUll{
return value == null ? default : value
}
function requiresNotNullString(): void
var name: string | null;
var checkedName: string = defaultValue(name, "Fred");
To clarify, if the input of the function is a type of string | null
, I want the return type to be just string
.
Do you think this can be achieved?