title: How can I destructure parameters on a function such that it can receive either the entire object or just a part of it?
body: <p>For example, I have a vehicle object as</p>
  <pre><code>vehicle: {
    make: { //say type Make
      name: &quot;acura&quot;,
      model: &quot;rdx&quot;
    },
    user: { //say type User
      name: &quot;abc&quot;,
      age: 30
    },
    addr: { //say type Address
      number: 12,
      street: 'xyz ave'
    }
  }
  </code></pre>
  <p>I want to write a function that can either receive the entire object or a partial object. So I did</p>
  <pre><code>function display({make}: {make?: Make} = {}, {user}: {user?: User} = {}, {addr}: {addr?: Address} = {}): void {
    if(make) {
      console.log(make.name);
    }
    if(user) {
      console.log(user.name);
    }
    if(addr) {
      console.log(addr.num);
    }
  }
  display(vehicle); // Should display acura, abc, 12
  display(vehicle.user); // Should display abc
  </code></pre>
  <p>Now, the above function works if I just pass the make or the entire vehicle object. Except of course it takes it as only the first parameter and the rest are undefined. How do I destructure the params properly to pass either a partial object or the entire object?</p>
  <p><a href="https://www.typescriptlang.org/play?module=1#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgNWAAsFsAbPAbwFgAoOOAW0wGtgAuOAWVeABo6DAK4BnNJwCqYqAPpxMAEwVROAQSVRgIkXQC%20dOqEixEKNFlzdecGnKSZGHOCJhRkAc1kNGEBcDKcLm5I7noGtEbQ8MioGDh4Umg2gnD2joGuHl7y7k5IQowARmhhtIbgUaaxFnjqyloiyXYFnPlFaNlBwMAwGcGhtPpltBTwAG7EpBSchCTkeAC8Td68nJRwKQxpTgBEOEJQmDvZ3r7%20nDtQCiA7KbrZouI2G3JbDruYhdjHmzlOAMwABju2UUyjWLwYWxacAAjAAmE7OVzdXpwADkIAAngAveQTdF3Up0dBCJDYGAICBIOAKBAiMBkTBYgAUlGYbF0aw5wAA-JweJy4EtKPcbI8oFzxdJ%20XBEpLhTYxZQwZK1qrZXVNNpdIrRQBKThjCAIBTLRDoFk8-XmhjYakiCAUAB0ZAg7itvGd231AG4iXIEJaJTbbFC4PakI6XW6PRLve8-QGGEGWarQ79I9HgK73WmNN6Ckm5EMhnQ6QymayJnMKH64AB6BtwADKRAgQjIZorjOZ8mwB0wfHkX2HCPL9N71cm82dId9jebbY7Xdpk6rI%20wQA" rel="nofollow noreferrer">TS Playground</a></p>