ok
Return success
When processing is successful
import { Result } from 'types-ddd';
return Result.ok<T, F>(/* ... resource type T */);The resource accepts a generic type. It can be a primary type or a more dynamic type.
return Result.ok<string>("Hello World");It do not throw error and return an object with attributes and result status
const result = Result.ok<string>("simple string");
console.log(result)
> Result {
isSuccess: true,
isFailure: false,
error: null,
_value: "simple string",
statusCodeNumber: 200,
statusCode: "OK"
}
The returned value must be accessed by your key to get a result
How to confirm that the return is really successful
How to return an interface
If you declared the return as an interface and returned a value other than the one defined. You will have an error
Result also accpet statusCode optionally, if you want to provide domain status for infra.
You also can return a void using Result.success instead Result.ok. Let's see a real use case
It is possible to define an internationalization error message
Last updated
Was this helpful?