✔️
types-ddd
  • Introduction
  • Result
    • ok
    • success
    • fail
    • combine
  • UniqueEntityID
  • BaseDomainEntity
  • ValueObject
  • Entity
  • AggregateRoot
    • IHandle
    • IDomainEvent
    • DomainEvents
  • WriteList
    • ReadList
  • IUseCase
  • IBaseConnection
  • BaseRepository
  • IRepository
  • Filter
  • IMapper
  • Utils
    • SpecificationComposite
    • ChangesObserver
Powered by GitBook
On this page

Was this helpful?

  1. Result

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.ok

This one the argument is required, you always must provide a value to return

Result.success

This one the argument is optional.

When to use It?

When you have a function that return void

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

PreviousokNextfail

Last updated 3 years ago

Was this helpful?