title: Typescript - setState callback function
body: <p>I am trying to add types to the argument of a callback function within a setState function that updates its previous value (see below). The argument &quot;previous&quot; has to adhere to the &quot;Previous&quot; type; yet when writing that, I get the following error:</p>
  <blockquote>
  <p>Argument of type '(previous: Previous) =&gt; { oneArg: number;
  anotherArg: number; }[]' is not assignable to parameter of type '[] |
  { oneArg: number; anotherArg: number; }[]'.   Type '(previous:
  Previous) =&gt; { oneArg: number; anotherArg: number; }[]' is missing the
  following properties from type '{ oneArg: number; anotherArg: number;
  }[]': pop, push, concat, join, and 28 more.ts(2345)</p>
  </blockquote>
  <p>Anybody could help me out?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>type Previous = {
    oneArg: number;
    anotherArg: number;
  }[] | [];
  
  
  type Props = {
  setState: (arg: { oneArg: number; anotherArg: number }[] | []) =&gt; void;
  }</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction(someArg: number) {
      props.setState((previous) =&gt; {
        return previous.filter((element, index) =&gt; {
            return index !== someArg;
          },
        );
      });
    }</code></pre>
  </div>
  </div>
  </p>