11 lines
460 B
TypeScript
Raw Normal View History

2024-08-15 12:08:41 +02:00
import { type CodexError } from "../errors/errors";
2024-08-15 12:08:15 +02:00
/**
* SafeValue is a type used for error handling instead of throwing errors.
* It is inspired by Go's "error as value" concept.
* If the value represents an error, `error` is true and `data` will contain the error.
* If the value is not an error, `error` is false and `data` will contain the requested data.
*/
export type SafeValue<T> = { error: false, data: T } | { error: true, data: CodexError }