async function getData(): Promise<Result<Data>> {
if (error) {
errorStack.stack_push("error", "Failed to get data");
return Err();
}
return Ok(data);
}
const result = await getData();
if (!result.ok) {
// Can't access result.value here - TypeScript error
console.log(errorStack.stack_search("data"));
return;
}
// TypeScript knows result.ok === true, so .value exists
useData(result.value);
Result type representing success or failure.