title: How to declare a module in TypeScript with an object as default export
body: <p>In a TypeScript project, I would like to use a third-party library that does not provide type definitions. So I need to come up with my own module declaration. What the module basically exports looks like this:</p>
  
  <pre><code>const foo = {
    bar () {
      return 23;
    }
  };
  
  module.exports = foo;
  </code></pre>
  
  <p>So, the question now is how to come up with the module declaration. First of all, it's obvious that the module uses a <code>default</code> export, not a named one. This default export is an object, which has methods. So I tried this:</p>
  
  <pre><code>declare module 'foo' {
    export default {
      bar(): number;
    };
  }
  </code></pre>
  
  <p>However, the TypeScript compiler complains that:</p>
  
  <blockquote>
    <p>The expression of an export statement must be an identifier or a qualified name in an ambient context.</p>
  </blockquote>
  
  <p>What does this mean? Using <code>bar</code>, I have used an identifier, haven't I? And what does "qualified name in an ambient context" mean?</p>