title: Typescript extend third-party declaration files
body: <p>How can I extend third-party declaration files?<br />
  for example, I want to extend <code>Context</code> from <a href="https://github.com/DefinitelyTyped/DefinitelyTyped/blob/616c84c0e73295a78a94b96276da833dcafe9ea0/types/koa/index.d.ts#L644" rel="noreferrer">@types/koa</a> and add an extra field(<code>resource</code>) to it.<br />
  I tried this:</p>
  <pre><code>// global.d.ts
  declare namespace koa {
      interface Context {
          resource: any;
      }
  }
  </code></pre>
  <p>But it doesn't work:</p>
  <pre><code>error TS2339: Property 'resource' does not exist on type 'Context'.
  </code></pre>
  <h2>Update</h2>
  <p>a simplified version of my code which produces this error:</p>
  <pre><code>import {Context} from 'koa';
  import User from './Models/User';
  class Controller {
     async list(ctx: Context) {
          ctx.resources = await User.findAndCountAll();
          ctx.body = ctx.resources.rows;
          ctx.set('X-Total-Count', ctx.resources.count.toString());
          ctx.status = 200;
      }
  }
  </code></pre>
  <blockquote>
  <p>typescript v2.4</p>
  </blockquote>
  <pre><code>// tsconfig.json
  {
    &quot;compilerOptions&quot;: {
      &quot;target&quot;: &quot;es6&quot;,
      &quot;module&quot;: &quot;commonjs&quot;,
      &quot;moduleResolution&quot;: &quot;node&quot;,
      &quot;noImplicitAny&quot;: true,
      &quot;experimentalDecorators&quot;: true,
      &quot;emitDecoratorMetadata&quot;: true
    },
    &quot;exclude&quot;: [
      &quot;node_modules&quot;
    ]
  }
  </code></pre>