typings\global.d.ts:
declare global {
namespace NodeJS {
interface Global {
isServerRunning: boolean;
}
}
}
依然不起作用,求大神帮忙看看,谢谢,(・ω・)ノ
========================问题更新================
目前定义普通的变量如下没问题:
typings\global.d.ts:declare var isServerRunning: boolean;
但是如果定义一个全局的class属性还是不行,比如:
exception.ts
export default class ExceptionConstructor extends Error {
...
}
typings\global.d.ts:
import ExceptionConstructor from 'expection.ts';
declare var Exception: ExceptionConstructor;
然后在代码里:
import ExceptionConstructor from 'expection.ts';
global.Exception = ExceptionConstructor;
就不行:
同时上面定义的isServerRunning也不起作用了
这种能全局定义吗
直接使用
var
定义变量即可。如:直接在
.d.ts
中使用var
声明也是可以的参考:TypeScript: Documentation - TypeScript 3.4 (typescriptlang.org)