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

后端 未结 4 1247
陌清茗
陌清茗 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:46

    Edit: Answering my own question.

    Google's documentation explicity says this:

    Warning: do not call Promise.resolve() and similar with the result of gapi.auth2.init(). As the GoogleAuth object returned implements the then() method that resolves with itself, it will create an infinite recursion.

    This means there will be trouble whether we're using Typescript or even plain Javascript.

    So here Typescript is protecting the user from an infinite recursion. Whether or not that is it's intention, I don't know. The wording seems to suggest it's issue is entirely a typing problem or limitation of the compiler. But it's actually doing an important job.

    TL;DR: The promise result is another promise which returns itself. The compiler error is guarding against infinite recursions.

提交回复
热议问题