1

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.

1 Answer 1

2

If you need to be able to call new a.A(), do:

declare class A { A: typeof A; } declare const a: A; declare namespace a { export type A = A; } export = a; 

If you only need the type a.A accessible, do:

declare const a: a.A; declare namespace a { interface A {} } export = a 
Sign up to request clarification or add additional context in comments.

1 Comment

I think you need to keep declare class A { A: typeof A }, otherwise you can't do new a.A(), as a.A only refers to a type.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.