success
Basically It is used when you want to return nothing as value, just return a success
import { Result } from 'types-ddd';
return Result.success<T, F>();
Result.okThis one the argument is required, you always must provide a value to return
Result.successThis one the argument is optional.
When to use It?
import { Result } from 'types-ddd';
const SumLessThanTenAndPrintResult = (n1: number, n2: number): Result<void> => {
const sumResult = n1 + n2;
console.log(sumResult);
if (sumResult >= 10) {
return Result.fail("Result is greater than ten");
}
return Result.success();
}
const result = SumLessThanTenAndPrintResult(2, 3);
> 5
console.log(result.isSuccess);
> true
console.log(result.getResult());
> null
Always the returned result value from success method will be null.
If you need to get the returned value use Result.ok
Last updated
Was this helpful?