[英]Augmenting global in TypeScript
如何將fetch
添加到 TypeScript 中的全局對象上,這樣我就不必這樣做了:
(global as any).fetch
我已經在./types/index.d.ts
的文件中嘗試過這個
並嘗試通過將其包含在 tsconfig.json 中來引用它。
如果您在global
上使用Go to Definition ,您將看到它在節點定義文件中聲明為:
declare var global: NodeJS.Global;
所以為了給它添加東西,你只需要在NodeJS
命名空間中增加Global
接口:
declare namespace NodeJS {
export interface Global {
fetch(u: string): string
}
}
global.fetch("") // ok now
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.