nodejs+typescript项目中添加全局global属性
# nodejs+typescript项目中添加全局global属性
比如增加pp属性
# 无引用其他模块
declare namespace NodeJS {
interface Global {
pp: any;
}
}
需在当前页面进行声明,修改global对象
# 有引用其他模块
import xxx from 'xxx'
declare global {
namespace NodeJS {
interface Global {
pp: any;
}
}
}
把这个global.d.ts文件放入到src/types/文件夹下,并修改tsconfig.json
{
"paths": {
"*": ["node_modules/*", "src/types/*"]
}
}
上次更新: 2022/01/20, 16:31:34