Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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 如何在全局上下文中扩充模块?_Typescript_Module_Typescript2.0 - Fatal编程技术网

Typescript 如何在全局上下文中扩充模块?

Typescript 如何在全局上下文中扩充模块?,typescript,module,typescript2.0,Typescript,Module,Typescript2.0,我有一个特殊的打字文件,它有一个像这样的现代形状 // something.d.ts declare function something(...): ...; declare namespace something { interface A { ... } interface B { ... } } export = something; export as namespace something; 我试图在文件中使用这个不是模块的模块,所以官方的模块扩展不起作用。我的任务是向

我有一个特殊的打字文件,它有一个像这样的现代形状

// something.d.ts

declare function something(...): ...;
declare namespace something {
  interface A { ... }
  interface B { ... }
}

export = something;
export as namespace something;
我试图在文件中使用这个不是模块的模块,所以官方的模块扩展不起作用。我的任务是向
something
命名空间根添加另一个函数,并向
A
接口添加另一个函数

我曾尝试使用名称空间合并,但它似乎不起作用,因为它没有合并,而是认为我的声明是唯一的声明,因此来自打字文件的原始内容根本不可见

// myGlobalFile.ts

declare namespace something {
  function extraFunction();

  interface A {
    extraFunctionOnA();
  }
}
就界面扩展而言,我还尝试了一些愚蠢的语法,如

// myGlobalFile.ts

interface something.A {
  extraFunctionOnA();
}
当然,这是一个语法错误,所以它不可能工作,但它相当好地代表了我目标的一半


如何在处理全局范围的文件中扩展此模块?

我遇到了类似的问题,在github上遇到了您的问题。我认为在这里留下一个链接是明智的: