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:
const foo = {
bar () {
return 23;
}
};
module.exports = foo;
So, the question now is how to come up with the module declaration. First of all, it's obvious that the module uses a default
export, not a named one. This default export is an object, which has methods. So I tried this:
declare module 'foo' {
export default {
bar(): number;
};
}
However, the TypeScript compiler complains that:
The expression of an export statement must be an identifier or a qualified name in an ambient context.
What does this mean? Using bar
, I have used an identifier, haven't I? And what does "qualified name in an ambient context" mean?