Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method

后端 未结 4 1249
陌清茗
陌清茗 2021-01-02 04:24

An errors blows up when using the typings for the the Google Auth2 API - @types/gapi.auth2. The compiler throws an error 1062 if I create a promise

4条回答
  •  没有蜡笔的小新
    2021-01-02 04:47

    It is dangerous to use Promise with any objects with it's own then() method. See @gwilz answer. You will be trapped in an infinite loop!

    One way to workaround is to actually remove then() method:

    async function getGapi() {
      return new Promise>(resolve => {
        ...get auth object...
        delete auth.then;
        resolve(auth);
      });
    }
    

提交回复
热议问题