title: Subsequent variable declarations must have the same type. any
body: <p>I'm using ava (no link, since I'm not allowed to use more than 2 ) for testing and want to type ava's test context. It's <a href="https://github.com/avajs/ava/blob/master/types/base.d.ts#L103" rel="nofollow noreferrer">typed as <code>any</code> in ava's definition file</a>.</p>
  
  <p>What I specifically want is that the typescript compiler knows that <code>t.context</code> is of the type <code>{foo: number}</code> in the following test:</p>
  
  <pre><code>import test from 'ava'
  
  test.beforeEach((t) =&gt; {
    t.context = { foo: 5 }
  })
  
  test('Is context typed', (t) =&gt; {
    // uncaught typo
    t.is(t.context.fooo, 5)
  })
  </code></pre>
  
  <p>I tried to use <a href="http://www.typescriptlang.org/docs/handbook/declaration-merging.html" rel="nofollow noreferrer">declaration merging</a> to do this, but it fails with <code>TS2403: Subsequent variable declarations must have the same type.  Variable 'context' must be of type 'any', but here has type '{ foo: number; }'.
  </code>: </p>
  
  <pre><code>declare module 'ava' {
      interface ContextualTestContext {
        context: {
          foo: number,
        }
      }
  }
  
  test.beforeEach((t) =&gt; {
    t.context = { foo: 5 }
  })
  
  test('Is context typed', (t) =&gt; {
    // uncaught ypo
    t.is(t.context.fooo, 5)
  })
  </code></pre>
  
  <p>Is there a way to do this without casting the context all the time like so:</p>
  
  <pre><code>interface IMyContext {
    foo: number
  }
  
  test.beforeEach((t) =&gt; {
    t.context = { foo: 5 }
  })
  
  test('Is context typed', (t) =&gt; {
    const context = &lt;IMyContext&gt; t.context
    // caught typo
    t.is(context.fooo, 5)
  })
  </code></pre>