title: How can I infer the return type without a type variable?
body: <p>My goal is to create a function, that clones an array - and keeps the types. With this code, typescript declares the return type as any:</p>
  
  <pre class="lang-js prettyprint-override"><code>export function someFn(inputArray) {
      return [...inputArray];
  }
  // result will have any[] as type
  const result = someFn([1, 2, 3]);
  </code></pre>
  
  <p>How can I tell typescript, that the return type of <code>someFn</code> will be the same type as the input (i.e. in this case, an array of numbers?</p>
  
  <p><strong>Workaround</strong></p>
  
  <p>I know I can do this with a type variable:</p>
  
  <pre class="lang-js prettyprint-override"><code>export function someFn&lt;T&gt;(inputArray): T[] {
      return [...inputArray];
  }
  // result will have number[] as type (but only because I input T as number)
  const result = someFn&lt;number&gt;([1, 2, 3]);
  </code></pre>
  
  <p>I would like to avoid the above workaround because it forces me to declare the type beforehand.</p>