Skip to main content

SimpleResult<E>

SimpleResult<E> = { ok: true; } | { ok: false; error: E; }

A lightweight discriminated union for success/failure outcomes.

Use this when you need a typed return value without the full Result<T, E> class from Zygos. No methods, no runtime cost, just a plain object.


Type Parameters

E: E = string

The error type. Defaults to string.


Since

2.2.0


Example

function save(data: string): SimpleResult {
if (data.length > 1000) {
return { ok: false, error: 'Payload too large' }
}
return { ok: true }
}

const result = save(payload)
if (!result.ok) {
console.error(result.error)
}