createRelativePositionFromTypeIndex = (type, index, assoc = 0) => {
  let t = type._start;

  if (assoc < 0) {
    // associated to the left character or the beginning of a type, increment index if possible.
    if (index === 0) {
      return createRelativePosition(type, null, assoc);
    }

    index--;
  }

  while (t !== null) {
    if (!t.deleted && t.countable) {
      if (t.length > index) {
        // case 1: found position somewhere in the linked list
        return createRelativePosition(type, createID(t.id.client, t.id.clock + index), assoc);
      }

      index -= t.length;
    }

    if (t.right === null && assoc < 0) {
      // left-associated position, return last available id
      return createRelativePosition(type, t.lastId, assoc);
    }

    t = t.right;
  }

  return createRelativePosition(type, null, assoc);
}
Create a relativePosition based on a absolute position.

@param {AbstractType<any>} type The base type (e.g. YText or YArray).
@param {number} index The absolute position.
@param {number} [assoc]
@return {RelativePosition}

@function