createAbsolutePositionFromRelativePosition = (rpos, doc) => {
  const store = doc.store;
  const rightID = rpos.item;
  const typeID = rpos.type;
  const tname = rpos.tname;
  const assoc = rpos.assoc;
  let type = null;
  let index = 0;

  if (rightID !== null) {
    if (getState(store, rightID.client) <= rightID.clock) {
      return null;
    }

    const res = followRedone(store, rightID);
    const right = res.item;

    if (!(right instanceof Item)) {
      return null;
    }

    type =
    /** @type {AbstractType<any>} */
    right.parent;

    if (type._item === null || !type._item.deleted) {
      index = right.deleted || !right.countable ? 0 : res.diff + (assoc >= 0 ? 0 : 1); // adjust position based on left association if necessary

      let n = right.left;

      while (n !== null) {
        if (!n.deleted && n.countable) {
          index += n.length;
        }

        n = n.left;
      }
    }
  } else {
    if (tname !== null) {
      type = doc.get(tname);
    } else if (typeID !== null) {
      if (getState(store, typeID.client) <= typeID.clock) {
        // type does not exist yet
        return null;
      }

      const {
        item
      } = followRedone(store, typeID);

      if (item instanceof Item && item.content instanceof ContentType) {
        type = item.content.type;
      } else {
        // struct is garbage collected
        return null;
      }
    } else {
      throw error.unexpectedCase();
    }

    if (assoc >= 0) {
      index = type._length;
    } else {
      index = 0;
    }
  }

  return createAbsolutePosition(type, index, rpos.assoc);
}
@param {RelativePosition} rpos
@param {Doc} doc
@return {AbsolutePosition|null}

@function