Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method
You just need to omit then
from the type.
async function getGapi() {
return new Promise<Omit<gapi.auth2.GoogleAuth, "then">>(resolve => {
});
}
Edit: Answering my own question.
Google's documentation explicity says this:
Warning: do not call
Promise.resolve()
and similar with the result ofgapi.auth2.init()
. As the GoogleAuth object returned implements thethen()
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.
This is the way I found to circumvent this error
private async loadGapiAuth() {
await new Promise((resolve) => gapi.load('client:auth2', resolve));
await new Promise((resolve) => gapi.auth2.init(GAPI_CONFIG).then(resolve));
}
then I can do this:
await this.loadGapiAuth();
const auth = gapi.auth2.getAuthInstance();