typescript - ts 生成一个带有错误的 js(预期在 'case' 之前有一个 'break' 语句
问题描述
我有这个调用 api 并返回结果的打字稿代码
export default class ClientsService{
async GetClients() : Promise<IClientsModel[]>
{
let responseResult : IClientsModel[] = [] ;
const response = await fetch("https://localhost:5001/api/clients");
if (response.ok) {
const tmp = await response.json();
responseResult = JSON.parse(tmp) as ClientsModel[];
}
return responseResult ;
}
}
这会生成一个带有此错误的js:在“case”之前需要一个“break”语句。(案例 3 之前的行)
import { __awaiter, __generator } from "tslib";
var ClientsService = /** @class */ (function () {
function ClientsService() {
}
ClientsService.prototype.GetClients = function () {
return __awaiter(this, void 0, void 0, function () {
var responseResult, response, tmp;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
responseResult = [];
return [4 /*yield*/, fetch("https://localhost:5001/api/clients")];
case 1:
response = _a.sent();
if (!response.ok) return [3 /*break*/, 3];
return [4 /*yield*/, response.json()];
case 2:
tmp = _a.sent();
responseResult = JSON.parse(tmp);
_a.label = 3;
case 3: return [2 /*return*/, responseResult]; // Error here
}
});
});
};
return ClientsService;
}());
export default ClientsService;
//# sourceMappingURL=ClientsService.js.map
解决方案
推荐阅读
- r - 来自矩阵行的列联表
- python-3.x - 使用python复制文件并替换多个关键字
- php - 选择本地取货 Woocommerce 时可以在 2 个地址之间进行选择
- mysql - Mysql2::Error: Out of sort memory,考虑使用 docker-compose.yml 增加服务器排序缓冲区大小
- javascript - 如何摆脱 JavaScript 中的天数错误。在不同月份的两个连续日期获得相同的年龄差异
- c# - 通过 Azure 函数中的查询字符串调整图像大小
- c# - 始终使用 Microsoft Translator 获得 401
- python - 收到错误“找不到名称为“开始”的关键字。” 在使用机器人框架运行 sikuliLibrary 时
- python - 将列表(元组)列表转换为熊猫中的长数据框
- php - 警告:PDOStatement::execute():