我想使用地圖物件而不是呼叫 checkOrder 3 次。在這種情況下如何使用 via Map 而不是所有引數?:
管理員
class Admin{
async checkTest(
local: string,
suburb: string,
international: string
): Promise<void> {
await checkOrder(local, "Declined");
await checkOrder(suburb, "Declined");
await checkOrder(international, "Declined");
return;
}
}
測驗檔案
test("Test", async (t) => {
await Admin.checkTest(
"Local Place",
"Suburb Place",
"International Place"
);
);
}
uj5u.com熱心網友回復:
@Thomas 我想使用 map 物件而不是呼叫 checkOrder 3 次。
像這樣?
class Admin {
async checkTest(map: Map<Place, Status>) {
for (let [place, status] of map) {
await checkOrder(place, status);
}
}
}
和
test("Test", async (t) => {
await Admin.checkTest(
new Map([
["Local Place", "Declined"],
["Suburb Place", "Declined"],
["International Place", "Declined"],
])
);
});
uj5u.com熱心網友回復:
那么,在我的情況下使用正確的地圖嗎?
class Admin {
async checkTest(map: Map<string, string>) {
for (let [place, status] of map) {
await checkOrder(place, status);
}
}
}
和
test("Test", async (t) => {
await Admin.checkTest(
new Map([
["Local Place", "Declined"],
["Suburb Place", "Declined"],
["International Place", "Declined"],
])
);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/389566.html
標籤:javascript 打字稿 功能 测试 映射类型
下一篇:通過函式傳遞資料幀資料
