Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BmobPromise 无法使用 async/await 异步方法 #99

Open
yuzheng14 opened this issue Oct 21, 2022 · 1 comment
Open

BmobPromise 无法使用 async/await 异步方法 #99

yuzheng14 opened this issue Oct 21, 2022 · 1 comment

Comments

@yuzheng14
Copy link

typescript 中调用 Bomb.User.login() 时报错,出错代码:

const login = createAsyncThunk(
    'login/login',
    async ({ userId, passwd }: { userId: string, passwd: string }) => {
        let res = await Bomb.User.login(userId,passwd)
    }
)

报错:

类型在其自身的 "then" 方法的 fulfillment 回调中被直接或间接引用。

看声明文件中写的 export interface BmobPromise<T = any> extends Promise<BmobPromise<T>> {} 是 Promise 的子类,按理来说应该能用 async/await

@JslinSir
Copy link

JslinSir commented Jan 4, 2023

这样使用 如下:

export const loginApi = async (params: API.LoginParams):Promise<BmobAPI.CurrentUser> => {
   clearStoragedData()
   try {
      const res = await new Promise((resolve,reject) => Bmob.User.login(params.username, params.password).then(resolve).catch(reject));
      const result = res as BmobAPI.CurrentUser
      return result
   } catch (error:any) {
      if (error.code && error.code === 101) {
         throw new Error('用户名或密码错误')
      }
      throw error
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants