from typing import Dict
from typing import Any


def recursive_merge_dict(dict1: Dict[str, Any],
                         dict2: Dict[str, Any]) -> Dict[str, Any]:
  """Merge two dictionaries into a third dictionary recursively.

  Args:
    dict1: First dictionary to be merged.
    dict2: Second dictionary to be merged.

  Returns:
    A dictionary by merging the two dictionaries. If any of the values are
    dicts, they will be merged recursively.
  """
  res = dict1.copy()
  for k, v in dict2.items():
    if k in res and isinstance(res[k], dict):
      res[k].update(recursive_merge_dict(res[k], dict2[k]))
    else:
      res[k] = v
  return res