title: React typescript Object.assign return type
body: <p>I have this small custom hook which returns an <code>Object.assign</code> result. In documentation it says that this returns an array, but the example below can be used with array destructuring AND object destructuring.</p>
  
  <p>Code:</p>
  
  <pre><code>import { useState } from 'react';
  
  const useStateExtended = (initialValue, initialLoading = false) =&gt; {
  
    const [data, setData] = useState(initialValue);
    const [loading, setLoading] = useState(initialLoading);
  
    return Object.assign([data, setData, loading, setLoading], { data, setData, loading, setLoading })
  };
  
  export default useStateExtended;
  </code></pre>
  
  <p>This code can be used in the following ways:</p>
  
  <pre><code>const {data, setData, loading, setLoading} = useStateExtended({});
  const [data, setData, loading, setLoading] = useStateExtended({});
  </code></pre>
  
  <p>How does this work? Why can I destructure both like it is an array and an object?</p>
  
  <p>Secondly: How to type this in Typescript? Data types are:</p>
  
  <pre><code>data: any;
  setData: (data: any) =&gt; void;
  loading: boolean;
  setLoading: (boolean) =&gt; void;
  </code></pre>