refactor switchToType and assertType