使用Google Auth2 API键入错误时会出错@types/gapi.auth2。1062如果我创建一个使用gapi.auth2.GoogleAuth类型解析的承诺,则编译器将引发错误。
Type is referenced directly or indirectly in the fulfillment callback of its own 'then' method.
打字有个小怪癖:
class GoogleAuth {
...
/**
* Calls the onInit function when the GoogleAuth object is fully initialized, or calls the onFailure function if
* initialization fails.
*/
then(onInit: (googleAuth: GoogleAuth) => any, onFailure?: (reason: {error: string, details: string}) => any): any;
...
}
Run Code Online (Sandbox Code Playgroud)
使用的代码是这样的:
async function getGapi() {
return new Promise<gapi.auth2.GoogleAuth>(resolve => {
...
}); …Run Code Online (Sandbox Code Playgroud) typescript ×1