def validate_type(data_dict: dict, type_name: str) ->dict:
    """Ensure that dict has field 'type' with given value."""
    data_dict_copy = data_dict.copy()
    if 'type' in data_dict_copy:
        if data_dict_copy['type'] != type_name:
            raise Exception('Object type must be {}, but was instead {}.'.
                format(type_name, data_dict['type']))
    else:
        data_dict_copy['type'] = type_name
    return data_dict_copy
