Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在用TypeScript编写的npm包中正确地包含带有模块扩充的声明文件?_Typescript_Npm - Fatal编程技术网

如何在用TypeScript编写的npm包中正确地包含带有模块扩充的声明文件?

如何在用TypeScript编写的npm包中正确地包含带有模块扩充的声明文件?,typescript,npm,Typescript,Npm,我有一个npm包--tyranid-gracl--用typescript编写,并扩展了另一个包:tyranid,用javascript编写,但没有扩展 在我使用的泰兰德格拉克中。此外,我在package.json的typings字段中公开了为tyranid-gracl生成的.d.ts文件,以便允许第三方typescript库为tyranid-gracl进行打字 问题:我如何将tyranid gracl制作的tyranid的模块扩展正确地公开给第三个库,该库通过npm安装tyranid gracl

我有一个npm包--
tyranid-gracl
--用typescript编写,并扩展了另一个包:
tyranid
,用javascript编写,但没有扩展

在我使用的
泰兰德格拉克
中。此外,我在
package.json
typings
字段中公开了为
tyranid-gracl
生成的
.d.ts
文件,以便允许第三方typescript库为
tyranid-gracl
进行打字

问题:我如何将
tyranid gracl
制作的
tyranid
的模块扩展正确地公开给第三个库,该库通过npm安装
tyranid gracl

问题的基本提炼

第一个库的类型定义文件
tyranid

/**
*  Type definitions for tyranid.js
*/
export = TyrStatic;

declare namespace TyrStatic {

  // declare properties of Tyr object
  export namespace Tyr {

    interface Document {
      $id: string;
    }

  }
}
第二个库的模块扩展,
tyranid gracl

import { documentMethods as dm } from './tyranid/documentMethods';

declare module 'tyranid' {

  namespace Tyr {
    /**
    * Add additional methods to Document interface
    */
    interface Document {
      $allow: typeof dm.$allow;
      $deny: typeof dm.$deny;
    }
  }

}
我希望在开发人员通过npm安装
tyranid gracl
时进行上述修改。目前,我在
tyranid gracl
index.d.ts
中引用了上述修改,但它似乎不起作用——特别是,添加的方法对类型系统不可见


希望这是有意义的——提前感谢

乍一看,您的
Tyraid gracl
打字中是否缺少
导出
命名空间Tyr
。我认为对于扩展现有名称空间,扩展文件不会导出(或者它会覆盖?),至少对我来说是这样。