title: Is there a way to return extended object without knowting it?
body: <p>Let's assume that we have code as below. I would like to copy User object without knowing that he may be agent, and after copy I would like to receive Agent object if he was that object.</p>
  <p>My goal would like to be some parsing function inside User so I don't have to check for object in later use cases.</p>
  <p>Is there any way to return Agent object without knowing about it? Or I have to check if its Agent and then use something like this <code>(user as Agent).copyWith()</code>. It would be nice if I could avoid that.</p>
  <p>Thanks in advance for any help.</p>
  <pre><code>class User {
          final String name;
      
          User(this.name);
      }
      
      
      class Agent extends User {
          Agent(super.name);
      }
      
      
      main() {
          final agent = Agent('name');
          runFunction(agent);
      }
      
      void runFunction(User user) {
      
          if(user is Agent) // true
      
          final copiedUser = user.copyWith(name: newName);
      
          if(copiedUser is Agent) // false
      
      }
  </code></pre>