A runtime assertion throws on null but uses a predicate signature instead of asserts.
Codetypescript
function assertIsDefined<T>(value: T): value is NonNullable<T> {
if (value === undefined || value === null) {
throw new Error("Not defined");
}
}
function use(x: string | null) {
assertIsDefined(x);
console.log(x.toUpperCase());
}