If you need to create an instance with a specific type (as you do whenever you
are not constructing immediately for a function return or as an argument to a
function), you can use a type parameter:
constnotString = Result.err<number, string>('something went wrong');
Note: passing nothing, or passing null or undefined explicitly, will
produce a Result<T, Unit>, rather than producing the nonsensical and in
practice quite annoying Result<null, string> etc. See Unit for
more.
In the context of an immediate function return, or an arrow function with a
single expression value, you do not have to specify the types, so this can be
quite convenient.
Create an instance of
Err
.If you need to create an instance with a specific type (as you do whenever you are not constructing immediately for a function return or as an argument to a function), you can use a type parameter:
Note: passing nothing, or passing
null
orundefined
explicitly, will produce aResult<T, Unit>
, rather than producing the nonsensical and in practice quite annoyingResult<null, string>
etc. SeeUnit
for more.In the context of an immediate function return, or an arrow function with a single expression value, you do not have to specify the types, so this can be quite convenient.
Template: T
The type of the item contained in the
Result
.Param: E
The error value to wrap in a
Result.Err
.