Optionalmessage: stringThe message to set in the error that is thrown
class ProblemLogger {
problem?: string;
log() {
assert(this.problem, "You must set problem before logging it");
// now typescript knows `this.problem` is truthy, so we can safely call methods on it
console.log(problem.toUpperCase());
}
}
Throws an error if
conditionis falsy, and acts as a type guard.