我有一个函数(getLocalSecurity),它从命令提示符处获取一个参数并返回布尔值,如下所示:
server.ts:
import { getDataService } from './service';
import { getInternalService } from './internal/service';
import { ServiceFactory } from './services/serviceFactory';
import { loggers } from 'winston';
const LOG = loggers.get('server');
const mainApp = getDataService();
const cla = require('command-line-arguments');
const params = cla.getCommandLineArguments();
export function getLocalSecurity(): boolean {
return params.LOCAL_SECURITY;
}
LOG.info('Starting server on port 9090...');
在另一个typeScript文件上,我想使用它:
import {getLocalSecurity} from './server';
if (getLocalSecurity()) {
console.log('access denied', getLocalSecurity());
return Promise.resolve({});
}
当我在命令提示符下使用以下语句时,console.log中的getLocalSecurity为false,但如果条件为true,则为LocalLocalSecurity。问题是什么?我该如何解决?
npm run start --- LOCAL_SECURITY -false
return不是布尔值,它是一个字符串,我不知道为什么!在if条件下,我们必须使用以下内容:
if (getLocalSecurity() === 'false')....
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句