[英]Exported function doesn't work in if statement in TypeScript
I have a function (getLocalSecurity) which gets an argument from command prompt and return boolean, as you see here: 我有一个函数(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...');
On the other typeScript file I want to use it: 在另一个typeScript文件上,我想使用它:
import {getLocalSecurity} from './server';
if (getLocalSecurity()) {
console.log('access denied', getLocalSecurity());
return Promise.resolve({});
}
when I use the following sentence in command prompt, getLocalSecurity is false in console.log but in if condition it is true. 当我在命令提示符下使用以下语句时, console.log中的 getLocalSecurity为false,但如果条件为true,则为LocalLocalSecurity。 What is the problem? 问题是什么? How can I fix it? 我该如何解决?
npm run start --- LOCAL_SECURITY -false
return is not a boolean, it is a string, I don't know why !!!!!!! return不是布尔值,它是字符串,我不知道为什么! In if condition we have to use the following: 在if条件下,我们必须使用以下内容:
if (getLocalSecurity() === 'false')....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.