2017-10-18 52 views
2

我有一個函數(getLocalSecurity),後者從命令提示符下的參數,並返回boolean值,因爲你在這裏看到:導出功能不if語句工作在打字稿

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...'); 

另打字稿文件I想使用它:

import {getLocalSecurity} from './server'; 

if (getLocalSecurity()) { 
    console.log('access denied', getLocalSecurity()); 
    return Promise.resolve({}); 
} 

,當我使用命令提示符下面的句子,getLocalSecurity是虛假的,的console.log如果條件這是真的。 問題是什麼?我該如何解決它?

npm run start --- LOCAL_SECURITY -false 
+0

是否嘗試過移動'cla.getCommandLineArguments()'導出的函數內只返回之前; – bhantol

+0

我試過了。沒有不同。 – Sohrab

回答

0

返回不是布爾值,它是一個字符串,我不知道爲什麼!!!!!!! 在if條件,我們必須使用以下命令:

if (getLocalSecurity() === 'false')....