def METHOD_NAME(encoded_key: bytes) -> types.FPLKeyType:
  """Decode an encoded dictionary key encoded with encode_key.
  Args:
    encoded_key: Dictionary key, encoded with encode_key.
  Returns:
    Decoded dictionary key.
  Raises:
    ValueError: We couldn't decode the encoded key.
  """
  if encoded_key.startswith(_TUPLE_KEY_PREFIX):
    parts = encoded_key[len(_TUPLE_KEY_PREFIX):].split(b'$', 1)
    if len(parts) != 2:
      raise ValueError('invalid encoding: %s' % encoded_key)
    elem_count = int(parts[0])
    parts = parts[1].split(b'$', elem_count)
    if len(parts) != elem_count + 1:
      raise ValueError('invalid encoding: %s' % encoded_key)
    lengths = map(int, parts[:elem_count])
    parts = parts[elem_count]
    elems = []
    for length in lengths:
      elems.append(parts[:length].decode('utf8'))
      parts = parts[length + 1:]  # Add one for the $ delimiter
    return tuple(elems)
  elif encoded_key.startswith(_BYTES_KEY_PREFIX):
    return encoded_key[len(_BYTES_KEY_PREFIX):].decode('utf8')
  else:
    raise ValueError('invalid encoding: %s' % encoded_key)