如何使index.ts中的某些行不执行? [英] how to make some lines in index.ts not executed?
问题描述
所以在我的 index.ts
中,我最初有这样的代码
从"./firestore/triggers/users/users_triggers"中以用户身份导出*;从"./firebase_authentication/triggers/firebase_auth_triggers"中将*导出为auth;
,然后我的 index.ts
中还有另一个 export
,但是我希望仅在满足某些条件的情况下执行此导出.所以在我的 index.ts
中会像这样
从"./firestore/triggers/users/users_triggers"中以用户身份导出*;从"./firebase_authentication/triggers/firebase_auth_triggers"中将*导出为auth;const MeetSomeCriteria = true;如果(meetSomeCriteria)返回;//如果符合某些条件,那么我希望下面的代码不会被触发从"./utilities/emulators/http_triggers/for_testing_via_firestore_emulators"中将*导出为实用程序;
但是如果我这样返回我会出错
那么如何使index.ts中的某些行不执行?
这些导出实用程序实际上是一些仅用于Firebase模拟器的功能.我想避免将这些功能部署到生产中打字稿中没有条件导入或导出.也就是说,你不能写类似的东西
if(条件)从模块"导入x
但是您可以像这样解决它
import *作为"./your/module"中的utilimport;导出const实用程序= MeetSomeCriteria?实用导入: 不明确的;
so in my index.ts
I initially have code like this
export * as users from "./firestore/triggers/users/users_triggers";
export * as auth from "./firebase_authentication/triggers/firebase_auth_triggers";
and then I have another export
in my index.ts
, but I want this export only executed if it meets some criteria. so in my index.ts
will be like this
export * as users from "./firestore/triggers/users/users_triggers";
export * as auth from "./firebase_authentication/triggers/firebase_auth_triggers";
const meetSomeCriteria = true;
if (meetSomeCriteria) return;
// if it meets some criteria, then I expect the code below won't be triggered
export * as utilities from "./utilities/emulators/http_triggers/for_testing_via_firestore_emulators";
but I will have error if I have return like that
so how to make some lines in index.ts not executed?
those export utilities is actually some functions that I will be used only for Firebase Emulators. I want to avoid those functions to be deployed in production
There are no conditional imports or exports in typescript. Ie you cannot write something like
if (acondition)
import x from "module"
But you can workaround it like this
import * as utilimport from "./your/module";
export const utilities = meetSomeCriteria
? utilimport
: undefined
;
这篇关于如何使index.ts中的某些行不执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!