简体   繁体   中英

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.

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM