// implicit-return export interface Result { isOk: () => this is Ok; isErr: () => this is Err; unwrap: () => T; } export class Ok implements Result { constructor(readonly value: T) {} isOk(): this is Ok { return true; } isErr(): this is never { return false; } unwrap() { return this.value; } } export class Err implements Result { constructor(public error: E) {} isOk(): this is never { return false; } isErr(): this is Err { return true; } unwrap(): never { throw new Error("unwrap...."); } } const idk = maybeIdk(); if (idk.isOk()) { if (idk.isOk()) { // no warnings } console.log(idk); console.log(idk.value); } const idk2 = maybeIdk(true); if (idk2.isErr()) { console.error(idk2); console.error(idk2.error); } export function maybeIdk(beep?: boolean) { if (beep) { return new Err(new Error("beep")); } return new Ok("boop"); }