【发布时间】:2018-12-02 23:39:07
【问题描述】:
我有几个这样的日志语句:
log.info('docker.r2g run routine is waiting for exit signal from the user. The container id is:', chalk.bold(process.env.r2g_container_id));
log.info('to inspect the container, use:', chalk.bold(`docker exec -it ${process.env.r2g_container_id} /bin/bash`));
log.info('to stop/kill the container, use kill, not stop:', chalk.bold(`docker kill ${process.env.r2g_container_id}`));
当我使用 tsc 进行转换时,我收到以下错误:
src/commands/run/run.ts(132,94): error TS2339: Property 'r2g_container_id' does not exist on type 'ProcessEnv'.
133 log.info('to stop/kill the container, use kill, not stop:', chalk.bold(`docker kill ${process.env.r2g_container_id}`));
将process.env 转换为any 或诸如此类的最佳方法是什么,以消除这些错误?或者也许我可以扩展 ProcessEnv 以包含我正在寻找的环境变量?不过前者似乎还不错。
我试过了:
declare global {
namespace NodeJS {
export interface ProcessEnv {
r2g_container_id: string,
docker_r2g_is_debug: string
}
}
}
但这不太对。
这是一个类似的问题,我们可以参考:using process.env in TypeScript
【问题讨论】:
标签: node.js typescript typescript2.0 tsc