我的代码:
const configPath = process.env[`${configPrefix}_CONFIG_PATH`]
? path.resolve(process.env[`${configPrefix}_CONFIG_PATH`])
: path.resolve('ab','config');
错误:
application/libs/config.ts:18:20 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.
18 ? path.resolve(process.env[`${configPrefix}_CONFIG_PATH`])
为什么要抱怨?我正在检查process.env[`${configPrefix}_CONFIG_PATH`]
上是否未定义,然后与?
和:
决定取哪个值。