Partially solved:
There is an old issue on github where this problem is described a bit. When you declare a module in a global scope, it rewrites the whole exported module's types. When you declare a module inside a module, it merges. Why? I have no idea
https://github.com/microsoft/TypeScript/issues/17736#issuecomment-344353174
I want to extend third party module's type by interface merging. Everything works fine, but when I comment
export {};
in types.d.ts I encounter the following error:
This expression is not callable. Type 'typeof import("koa-session")' has no call signatures
Could you explain why it happens?
You can check the working code here: https://codesandbox.io/s/typescript-node-nocfq?file=/src/types.d.ts