extractOkResult
extractOkResult<
T>(result):OkResult<T>
Defined in: core/src/utils/helper.ts:301
Helper function for extracting the value from a compiled result { Ok: T } or throw a CanisterError if { Err: E } Supports both uppercase (Ok/Err - Rust) and lowercase (ok/err - Motoko) conventions.
A Result is a variant, so only a variant arm is unwrapped: an object whose
one key is the tag, besides the _type discriminant a display-transformed
variant carries, which names that tag. A record that merely has a field named
ok or err next to others is a value like any other, and is returned
whole, also when that other field is a _type naming something else.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”result
Section titled “result”T
The compiled result to extract from.
Returns
Section titled “Returns”OkResult<T>
The extracted value from the compiled result.
Throws
Section titled “Throws”CanisterError with the typed error value if result is { Err: E } or { err: E }