@kaelyx/ts-kit / types / Result
Type Alias: Result<T, E>
Result<
T,E> = {ok:true;value:T; } | {error:E;ok:false; }
Defined in: types/result/result.types.ts:18
Represents the result of an operation that can either succeed with a value of type T or fail with an error of type E.
Type Parameters
T
T
E
E = Error
Union Members
Type Literal
{ ok: true; value: T; }
ok
ok:
true
true when the operation succeeded.
value
value:
T
The value the operation produced.
Type Literal
{ error: E; ok: false; }
error
error:
E
The error that describes why the operation failed.
ok
ok:
false
false when the operation failed.
Example
ts
const value: Result<number, string> = { ok: true, value: 42 }
const error1: Result<number, string> = { ok: false, error: 'Something went wrong' }
const error2: Result<number, Error> = { ok: false, error: new Error('Something went wrong') }
const error3: Result<number, SyntaxError> = { ok: false, error: new SyntaxError('Something went wrong') }