简体   繁体   English

扩展也是函数的.d.ts模块

[英]Extending a .d.ts module that is also a function

I'm attempting to extend (from definitely typed) locally: gm/gm.d.ts The module is a function as well as a namespace, and I need to add an additional invocation of the function. 我试图在本地扩展(从明确键入): gm / gm.d.ts模块是一个函数以及一个命名空间,我需要添加一个额外的函数调用。 I want to extend the current typing 我想扩展当前的输入

function m(image: string): m.State;

to also support 也支持

function m(readableStream:NodeJS.ReadableStream, image: string): m.State;

I'm currently running into the issue that any attempt to add the additional typing for the new function, ends up overwriting the entire module. 我目前遇到的问题是,任何为新功能添加额外输入的尝试都会覆盖整个模块。

Ultimately I will just submit a PR for the typing, but in general I would like the ability to augment the existing typings without a need for modifying the original file. 最终我只会提交打字的PR,但总的来说我希望能够增加现有的打字而无需修改原始文件。

Just define a function overload: 只需定义一个函数重载:

function m(image: string): m.State;
function m(readableStream:NodeJS.ReadableStream, image: string): m.State;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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