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
ont essayé mouvement 'cla.getCommandLineArguments()' l'intérieur de la fonction exportée juste avant le retour; – bhantol
Je l'ai essayé. aucune différence. – Sohrab