javascript - 如何在 .then() JS 中返回
问题描述
我有以下代码:
const fetchLoginData = async (): Promise<boolean> => {
fetch(urlWithParams, options)
.then((response) => response.json())
.then((json) => json.data.account.authentication_token)
.then((auth_token) => {
console.log(auth_token);
SecureStore.setItemAsync('Auth_Token', auth_token);
// here I want ot return TRUE
})
.catch((error) => {
console.error(error);
// here I want ot return FALSE
});
但是,如果我只是添加return true/false
而不是评论 - TS linter 会警告我,如果我根本没有回报。那么内部有条件返回的正确方法是什么fetch()
解决方案
推荐阅读
- r - 在 R 中循环遍历 glm
- linux - Linux:如何等待另一个进程阻塞 POSIX 信号量?
- jsrender - JsViews:使用深拷贝对象重新初始化模板:~root 问题
- c - 尝试写入结构数组的元素时出现分段错误
- cron - Cron - 每个星期天,除非是每月的第一天
- eclipse-jdt - 用于测试编译 Eclipse+Maven 的 Micronaut 注释处理器不起作用
- parameters - 当我调用一个函数调用的函数比我输入的参数多时会发生什么
- sql - 只包括有字母的记录,忽略列中有数字的记录
- opengl - OpenGL:alpha-to-coverage 交叉淡入淡出
- pandas - 如何让 pandas 为交叉乘法工作