Closed
Description
Consider the following example:
function takesGeneric<T>(t: T): void {
if (!isNullable<T>() || t != null){
// @ts-ignore
if (isDefined(t.call)){
t.call()
}
}
}
function callsGeneric<T>(t: T): void {
if (t != null) {
takesGeneric(t); // Would be nice to have a `notNull<T>` here
}
}
class Tee {
call(): void {
let x: i8 = 0;
}
}
let y: Tee | null = new Tee();
callsGeneric(y);
The type passed to takesGeneric
is no longer nullable since it's guaranteed to not be null. However, the type passed doesn't reflect this. A quick fix to this could be to add a new builtin that converts a type | null
to type
. Or in branches where the type is non-null this happens automatically.