小编vin*_*h10的帖子

打字稿:语法错误:意外的标记“导出”

在我的 React 项目中,我需要在 3 个打字稿项目之间共享模型(在我的例子中是打字稿接口)。所以我选择了 bit.env 并将所有模型导入到https://bit.dev/model/index/~code,一切都很好。

然后我需要验证模型中的字段,因此我将实用程序函数添加到https://bit.dev/model/index/~code#util.ts并将其部署到 bit.env

当我尝试在我的项目#2(我保存 firebase 云函数的地方)中使用此辅助函数时,我开始遇到以下错误。

/Users/vinoth.gopu/Documents/mine/oss/Cloud/functions/node_modules/@bit/model.index/dist/index.js:1
export * from './admin';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (internal/modules/cjs/loader.js:1101:16)
    at Module._compile (internal/modules/cjs/loader.js:1149:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1205:10)

Run Code Online (Sandbox Code Playgroud)

我在项目 #2 中的代码

export const placeOrder = functions
    .runWith({
        memory:'256MB'
    })
    .region(cloudConfig.firebase.region)
    .firestore
    .document('Orders/{OrderId}')
    .onCreate((snap, context) => {
        const orderDetails = snap.data() as UserOrders;

        try {
            //check if all fields of interface implemented
            if(isOrder(orderDetails)) { // PROBLEM HERE
                 //do something
            }

Run Code Online (Sandbox Code Playgroud)

正如上面代码中所指出的,我可以使用该模型项目中的所有接口,但辅助函数会抛出错误消息。

我参考了这些文章和链接

  1. 获得意外的令牌导出
  2. https://medium.com/the-node-js-collection/an-update-on-es6-modules-in-node-js-42c958b890c …

javascript node.js typescript babeljs

5
推荐指数
1
解决办法
1万
查看次数

加载页面时 Firebase auth.currentUser 为 null,当页面加载几毫秒后调用 authstatechange 时加载用户

我正在使用 React 和 Firebase 开发一个小型网络应用程序。为了处理身份验证,我使用了上下文 API,并在上下文中添加了登录用户的详细信息。

AuthProvider.tsx

const AuthProvider: React.FC = props => {
  const [state, setState] = useState<IAuthContext>(authInitialState);
  console.log("Inside AuthProvider");
  useEffect(() => {
    auth.onAuthStateChanged( user => {
      console.log("Auth State changed and user is ----->", user);
      if (user) {
        console.log("User value updated to the context")
        setState({
            ...authInitialState,
          isAuthenticated:!!user,
          permissions:[],
          user:user
        });
      }
      const stateChange = {
        ...authInitialState,
        isAuthenticated: !!user,
        user
      };
      // if (!user) {
        return setState(stateChange);
      // }
    });
  }, []);
  console.log("Rendering AuthProvider", state);
  return (
    <AuthContext.Provider value={state}>{props.children}</AuthContext.Provider>
  ); …
Run Code Online (Sandbox Code Playgroud)

javascript firebase reactjs firebase-authentication

2
推荐指数
1
解决办法
1562
查看次数

简单链表Vs STL :: list.哪一个最好?

简单链接列表:

struct Node { 
int x;
Node *next;
};
Run Code Online (Sandbox Code Playgroud)

使用STL的用户定义简单链表和列表容器的主要优点/缺点是什么?那些拥有大量数据的LL的列表性能怎么样?

c++ stl linked-list

0
推荐指数
2
解决办法
2754
查看次数