everweij/typescript-result

Chain map with async operations

florianbepunkt opened this issue · 1 comments

Currently it seems not possible to chain operations if they are async. The following code does not work

    const example = await Result.combine(EntityId.create(id), EntityId.create(gameId))
      .map(
        async ([id, gameId]) => await this.repository.get(this.repository.generateKey({ id, gameId })),
      )
      .map((character) => this.mapper.serialize(character));

Linter/IDE says Property 'map' does not exist on type 'Promise<JoinErrorTypes<DomainValidationError, Result<Error, Character, any>>>'.

However this works, although the syntax looks wrong imho.

    const example2 = (
      await Result.combine(EntityId.create(id), EntityId.create(gameId)).map(
        async ([id, gameId]) => await this.repository.get(this.repository.generateKey({ id, gameId })),
      )
    ).map((character) => this.mapper.serialize(character));

This should be fixed in the latest version (v2)