Hiranya Jayathilaka
Hiranya Jayathilaka

Reputation: 7438

Split a TypeScript declaration file with nested namespaces

Suppose I have the following ambient type declaration:

// index.d.ts
declare namespace admin {
  namespace auth {
    function doSomething();
  }
}

I can consume this as follows:

// caller.ts
import * as admin from './index';

admin.auth.doSomething();

Is there a way to split the d.ts file into two with no impact on the caller? Ideally I'd like to move the nested namespace auth to its own file auth.d.ts.

Upvotes: 1

Views: 561

Answers (1)

Hiranya Jayathilaka
Hiranya Jayathilaka

Reputation: 7438

Following seems to work:

// index.d.ts
import auth as _auth from './auth';

declare namesapce admin {
  export import auth = _auth;
}

Then in another file:

// auth.d.ts
export namespace auth {
  function doSomething();
}

Upvotes: 1

Related Questions