我有一个脚本,该脚本将使用预定义的绑定运行,例如response
。
我有一个TS界面,可以通知我的代码response
可以做什么。
如何让TypeScript知道此预定义变量存在?
这是我想要实现的:
import { HttpResponse } from './response';
// FIXME this binding already exists in the context of this script
let response: HttpResponse
// use response with type-checking
console.log(response.statusCode);
答案 0 :(得分:3)
您可以使用global scope augmentation使模块中的代码知道response
是在全局范围内定义的。
import { HttpResponse } from './response';
declare global {
let response: HttpResponse;
}