def merge_dicts(*dicts):
  """Merge dicts (list of dicts) into a new dictionary.

  Args:
    *dicts (tuple): A tuple contains dictionaries to be merged.

  Returns:
    dict: The merged dictionary.

  Raises:
    TypeError: If two dictionaries have the same key, the type of the key's
      value must be the same.
    ValueError: The type of two items whose keys are the same must be a list or
      a dictionary.
  """
  res = {}
  for d in dicts:
    for key, val in d.items():
      if key not in res:
        res[key] = val
      elif not isinstance(res[key], type(val)):
        raise TypeError('Dictionary item value conflict.')
      elif isinstance(res[key], list):
        res[key].extend(val)
      elif isinstance(res[key], dict):
        res[key] = merge_dicts(res, val)
      else:
        raise ValueError('Type should be a dictionary or a list')
  return res