2017-10-18 2 views
2

J'ai une fonction (getLocalSecurity) qui obtient un argument de ligne de commande et retour booléen, comme vous le voyez ici:fonction Exporté ne fonctionne pas si la déclaration dactylographiée

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

autre fichier tapuscrit I veulent l'utiliser:

import {getLocalSecurity} from './server'; 

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

lorsque j'utilise la phrase suivante dans l'invite de commande, getLocalSecurity est faux dans console.log mais si condition, il est vrai. Quel est le problème? Comment puis-je le réparer?

npm run start --- LOCAL_SECURITY -false 
+0

ont essayé mouvement 'cla.getCommandLineArguments()' l'intérieur de la fonction exportée juste avant le retour; – bhantol

+0

Je l'ai essayé. aucune différence. – Sohrab

Répondre

0

retour n'est pas un booléen, c'est une chaîne, je ne sais pas pourquoi !!!!!!! En si la condition que nous devons utiliser les éléments suivants:

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