小编Sim*_*ran的帖子

Git 存储错误“无法保存当前状态”

运行“git stash”时出现此错误

Cannot save the current status
Run Code Online (Sandbox Code Playgroud)

没有其他信息。

这是为什么?

git

10
推荐指数
3
解决办法
4613
查看次数

如何使用 Firebase 模拟器从单元测试中调用 Firebase 函数?

我正在运行 firebase 模拟器。

我的应用程序可以调用 firebase 云函数,如果允许用户(取决于数据库中的值),该函数可以创建自定义用户声明

我正在尝试调用该函数:


import * as firebase from '@firebase/testing';
import * as fs from 'fs';

const app = firebase.initializeTestApp({
  databaseName: 'mydb',
  auth: {
    uid: 'useruid'
  },
});

describe('Firebase Functions', () => {
  beforeEach(async () => {
    await firebase.loadDatabaseRules({
      databaseName: 'mydb',
      rules: fs.readFileSync('database.rules.json', 'utf8'),
    });
  });

  afterAll(async () => {
    await Promise.all(firebase.apps().map((app) => app.delete()));
  });

  const cloudfunction = app.functions().httpsCallable('cloudfunction')

  it('throws error if user is not authenticated', async () => {
    await firebase.assertFail(cloudfunction())
  })
});


Run Code Online (Sandbox Code Playgroud)

这是抛出一个错误:

错误:错误:预检响应具有无效的 HTTP …

javascript firebase-tools firebase-authentication google-cloud-functions

9
推荐指数
1
解决办法
2238
查看次数

刷新有嵌套路由的页面时出现“404 not found”,因为Vite没有将所有路由重定向到index.html

我可以使用 React 路由器的useNavigate钩子转到类似 的嵌套路由localhost:3000/nested/route,但是一旦重新加载,我就会收到 404 未找到错误,因为它试图localhost:3000/nested/route/index.html出于某种原因进行查找。

如何将开发中的Vite配置为具有客户端路由的SPA,以便所有请求都重定向到根index.html?

reactjs react-router vite

7
推荐指数
1
解决办法
2140
查看次数

如何使用 switch 语句使用条件类型来缩小类型范围?

我有一个“Food”对象,它可以有多种类型,具体取决于“category”属性的值。该对象来自json,因此之前不可能知道类型。

\n

我正在尝试在类别道具上使用 switch 语句,以便将 Food 对象转换为正确的类型

\n
\nexport type Category = \'fruit\' | \'grain\' | \'meat\'\n\ninterface Food<IngredientCategory extends Category> {\n  name: string;\n  category: IngredientCategory\n  [key: string]: string;\n}\n\ninterface Fruit extends Food<\'fruit\'> {\n  color: string;\n}\n\ninterface Grain extends Food<\'grain\'>{\n  size: string;\n}\n\ninterface Meat extends Food<\'meat\'> {\n  temperature: string\n}\n\ntype FoodFromCategory<IngredientCategory extends Category> = IngredientCategory extends \'fruit\' ? Fruit : IngredientCategory extends \'grain\' ? Grain : Meat;\n\nconst castFood = <IngredientCategory extends Category>(category: IngredientCategory, food: Food<any>):\n   Food<IngredientCategory> | undefined => {\n  switch (category) {\n    case "fruit":\n …
Run Code Online (Sandbox Code Playgroud)

typescript

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