Wednesday, 17 May 2017

Merging declarations of namespace and variable

I'm trying to create declaration file for a third-party library node-tap. The simplified problem is: for a library

// node_modules/a/index.js
function A() { /* ... */ }
module.exports = new A();
module.exports.A = A;

what would be a correct *.d.ts declaration file to allow the following code to compile successfully?

// test.ts
import * as a from 'a';
import {A} from 'a';
function f(): A {
    return a;
}

Mention that having A as type is important, even though it could be omitted in this simple example.



via polkovnikov.ph

No comments:

Post a Comment