Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 27 lines · 859 B · at 74947de

import { Some, None, Ok, Err, type Option, type Result } from "@tsus/runtime";// The word await appears only inside strings and comments, so these arms// stay synchronous and the match returns a plain string, not a Promise.const label = (o: Option<string>): string =>  match (o) {    Some(x) => `await ${x}`, // await in a template    None => "nothing to await",  };console.log(label(Some("me")));console.log(label(None));const slow = async (n: number): Promise<string> => {  await Promise.resolve();  return `slow ${n}`;};// A real await in one arm makes every arm async; the string one is untouched.const describe = async (r: Result<number, string>): Promise<string> =>  await match (r) {    Ok(n) => await slow(n),    Err(e) => "await failed: " + e,  };console.log(await describe(Ok(3)));console.log(await describe(Err("boom")));