当我使用打字稿来编译此功能时,它可以正常工作。但是,当我将babel与typescript插件一起使用时,它说checkForRenewedToken is not defined
let data;
let newToken;
await new Promise(resolve => {
(async function checkForRenewedToken() {
newToken = getToken()
if (!newToken) {
setTimeout(checkForRenewedToken, 1000); <--- checkForRenewedToken is not defined
} else {
data = await doCall(newToken);
resolve(data);
}
})();
});
return data;
要使babel开心,我必须这样更改它:
let data;
let newToken;
await new Promise(resolve => {
const checkForRenewedToken = async () => {
newToken = getToken()
if (!newToken) {
setTimeout(function () {
checkForRenewedToken(); <--- now it's happy
}, 1500);
} else {
data = await doCall(newToken);
resolve(data);
}
};
checkForRenewedToken();
});
return data;
为什么打字稿能够编译该行,但是带有@babel/preset-typescript
插件的babel无法编译?