【发布时间】:2022-01-15 15:22:32
【问题描述】:
我知道设置 .env 类型,我们在 .d.ts 中编写这段代码:
var process: {
env: {
MONGO_DB_URL: string;
}
}
但是如果我在全局声明中这样做,像这样:
declare global {
var process: {
env: {
MONGO_DB_URL: string;
}
}
module Express {
export interface Request {
decodedToken: DecodedToken;
}
export interface Application {
io: Server;
sessionQIDtoSocketMap: Record<string, string>;
}
}
}
它给了我这个错误:
var process: globalThis.NodeJS.Process
Subsequent variable declarations must have the same type. Variable 'process' must be of type 'Process', but here has type '{ env: { MONGO_DB_URL: string; }; }'.ts(2403)
globals.d.ts(44, 13): 'process' was also declared here.
如果我这样做:
declare var process: {
env: {
MONGO_DB_URL: string;
};
};
declare global {
module Express {
export interface Request {
decodedToken: DecodedToken;
}
export interface Application {
io: Server;
sessionQIDtoSocketMap: Record<string, string>;
}
}
}
【问题讨论】:
标签: node.js typescript .d.ts