Skip to content

Commit f441e4c

Browse files
committed
Improve type coverage
1 parent 4a3180b commit f441e4c

File tree

12 files changed

+102
-96
lines changed

12 files changed

+102
-96
lines changed

arbys.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ declare let currentHour: number;
2020
const days = [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ];
2121
const months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
2222

23-
function loc(key)
23+
function loc(key: string): string
2424
{
2525
return dict[key] ?? key;
2626
}
2727

28-
function totwo(num)
28+
function totwo(num: number): string
2929
{
3030
if (num < 10)
3131
{
3232
return "0" + num;
3333
}
34-
return num;
34+
return num.toString();
3535
}
3636

37-
function formattz(offset)
37+
function formattz(offset: number): string
3838
{
3939
if (offset == 0)
4040
{
@@ -49,7 +49,7 @@ function formattz(offset)
4949
}
5050
document.getElementById("local-time-option").textContent += " (" + formattz(new Date().getTimezoneOffset()) + ")";
5151

52-
function formathour(hour)
52+
function formathour(hour: number): string
5353
{
5454
switch ((document.getElementById("select-hourfmt") as HTMLSelectElement).value)
5555
{
@@ -111,7 +111,7 @@ Promise.all([
111111
onLanguageUpdate();
112112
});
113113

114-
function updateFilterNamesForLocale()
114+
function updateFilterNamesForLocale(): void
115115
{
116116
document.querySelector("label[for=filter-MT_SURVIVAL]").textContent = toTitleCase(dict["/Lotus/Language/Missions/MissionName_Survival"]);
117117
document.querySelector("label[for=filter-MT_DEFENSE]").textContent = toTitleCase(dict["/Lotus/Language/Missions/MissionName_Defense"]);
@@ -132,7 +132,7 @@ function updateFilterNamesForLocale()
132132
document.querySelector("label[for=filter-FC_MITW]").textContent = dict["/Lotus/Language/Game/Faction_MITW"];
133133
}
134134

135-
function updateLog()
135+
function updateLog(): void
136136
{
137137
console.time("updateLog");
138138

@@ -281,7 +281,7 @@ function updateLog()
281281
console.timeEnd("updateLog");
282282
}
283283

284-
function saveSettings()
284+
function saveSettings(): void
285285
{
286286
let hash = "days=" + encodeURIComponent((document.getElementById("select-days") as HTMLSelectElement).value)
287287
+ "&tz=" + encodeURIComponent((document.getElementById("select-tz") as HTMLSelectElement).value)

index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { IAbility, IArcane, ICustom, IExportEnemies, IFlavourItem, IGear, IPowersuit, IRecipe, IRegion, IRelic, IResource, ISentinel, IUpgrade, IWeapon, TMissionDeck } from "warframe-public-export-plus";
22

3+
interface IResult {
4+
type: string;
5+
key: string;
6+
value: any;
7+
}
8+
39
interface IRewardSource {
410
name: string[];
511
rotation?: number;
@@ -220,7 +226,7 @@ Promise.all([
220226
};
221227
});
222228

223-
function updateMissionDeckNames()
229+
function updateMissionDeckNames(): void
224230
{
225231
window.missionDeckNames = {
226232
"/Lotus/Types/Game/MissionDecks/SortieRewards": ["Sortie"],
@@ -259,10 +265,10 @@ function updateMissionDeckNames()
259265
});
260266
}
261267

262-
function doQuery(query: string)
268+
function doQuery(query: string): void
263269
{
264270
console.time("Input to language tags");
265-
let results = getDictEntriesFromQuery(query).reduce((arr, [key, value]) =>
271+
let results: IResult[] = getDictEntriesFromQuery(query).reduce((arr, [key, value]) =>
266272
{
267273
arr.push({ type: "tag", key, value });
268274
return arr;
@@ -587,7 +593,7 @@ function doQuery(query: string)
587593
}
588594

589595
if (!have_obtain_info
590-
&& result.key.substr(0, 48) == "/Lotus/Types/StoreItems/AvatarImages/FanChannel/"
596+
&& result.key.substring(0, 48) == "/Lotus/Types/StoreItems/AvatarImages/FanChannel/"
591597
)
592598
{
593599
let p = document.createElement("p");
@@ -780,7 +786,7 @@ function getDictEntriesFromQuery(query: string): [string, string][]
780786
});
781787
}
782788

783-
function resolveTagsToUses(results)
789+
function resolveTagsToUses(results: IResult[]): IResult[]
784790
{
785791
const res = [];
786792
outer: for (const result of results)
@@ -802,7 +808,7 @@ function resolveTagsToUses(results)
802808
return res;
803809
}
804810

805-
function addUniqueNameResults(res, query)
811+
function addUniqueNameResults(res: IResult[], query: string): void
806812
{
807813
query = query.toLowerCase();
808814
for (const [type, entries] of Object.entries(window.meta_entries))

live.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ ExportChallenges_promise.then(res => { (window as any).ExportChallenges = res; }
192192
ExportMissionTypes_promise.then(res => { (window as any).ExportMissionTypes = res; });
193193
ExportFactions_promise.then(res => { (window as any).ExportFactions = res; });
194194

195-
function formatExpiry(expiry)
195+
function formatExpiry(expiry: number): string
196196
{
197197
expiry -= expiry % 1000; expiry += 1000; // normalise the ms so everything ticks at the same time
198198
const time = Date.now();
@@ -204,7 +204,7 @@ function formatExpiry(expiry)
204204
return deltaToUnits(delta).join(" ");
205205
}
206206

207-
function deltaToUnits(delta)
207+
function deltaToUnits(delta: number): string[]
208208
{
209209
delta = Math.abs(delta);
210210

@@ -228,29 +228,29 @@ function deltaToUnits(delta)
228228
return units;
229229
}
230230

231-
function formatActivation(activation)
231+
function formatActivation(activation: number): string
232232
{
233233
return deltaToUnits(Date.now() - activation)[0];
234234
}
235235

236-
function createExpiryBadge(expiry)
236+
function createExpiryBadge(expiry: number): HTMLSpanElement
237237
{
238238
const span = document.createElement("span");
239-
span.setAttribute("data-expiry", expiry);
239+
span.setAttribute("data-expiry", expiry.toString());
240240
span.className = "badge text-bg-secondary";
241241
span.textContent = formatExpiry(expiry);
242242
return span;
243243
}
244244

245-
function setDatum(name, value, expiry)
245+
function setDatum(name: string, value: string, expiry: number): void
246246
{
247247
const elm = document.getElementById(name);
248248
elm.querySelectorAll("[data-bs-toggle=tooltip]").forEach(x => window.bootstrap.Tooltip.getInstance(x).dispose());
249249
elm.textContent = value + " ";
250250
elm.appendChild(createExpiryBadge(expiry));
251251
}
252252

253-
function updateVallis()
253+
function updateVallis(): void
254254
{
255255
const EPOCH = new Date("November 10, 2018 08:13:48 UTC").getTime();
256256
const time = Date.now();
@@ -466,7 +466,7 @@ function updateIncursions()
466466
setTimeout(updateIncursions, window.incursions_expiry - Date.now());
467467
}
468468

469-
function addTooltip(elm, title)
469+
function addTooltip(elm: HTMLElement, title: string): any
470470
{
471471
elm.setAttribute("data-bs-toggle", "tooltip");
472472
elm.setAttribute("data-bs-title", title);
@@ -871,7 +871,7 @@ const sortieModifiers = {
871871
"SORTIE_MODIFIER_BOW_ONLY": "Bow Only",
872872
};
873873

874-
function setWorldStateExpiry(expiry)
874+
function setWorldStateExpiry(expiry: number): void
875875
{
876876
if (Date.now() > expiry)
877877
{
@@ -890,8 +890,8 @@ async function updateSorties()
890890
await ExportMissionTypes_promise;
891891

892892
const sortie = window.worldState.Sorties.find(x => Date.now() >= parseInt(x.Activation.$date.$numberLong) && Date.now() < parseInt(x.Expiry.$date.$numberLong));
893-
setWorldStateExpiry(sortie.Expiry.$date.$numberLong);
894-
setDatum("sortie-header", toTitleCase(osdict["/Lotus/Language/Menu/SortieMissionName"]), sortie.Expiry.$date.$numberLong);
893+
setWorldStateExpiry(parseInt(sortie.Expiry.$date.$numberLong));
894+
setDatum("sortie-header", toTitleCase(osdict["/Lotus/Language/Menu/SortieMissionName"]), parseInt(sortie.Expiry.$date.$numberLong));
895895
document.getElementById("sortie-header").innerHTML += " ";
896896
document.getElementById("sortie-header").appendChild(createCompletionToggle(sortie._id.$oid));
897897
const tbody = document.createElement("tbody");
@@ -915,8 +915,8 @@ async function updateSorties()
915915
window.last_sortie = sortie._id.$oid;
916916

917917
const litesortie = window.worldState.LiteSorties.find(x => Date.now() >= parseInt(x.Activation.$date.$numberLong) && Date.now() < parseInt(x.Expiry.$date.$numberLong));
918-
setWorldStateExpiry(litesortie.Expiry.$date.$numberLong);
919-
setDatum("litesortie-header", osdict["/Lotus/Language/WorldStateWindow/LiteSortieMissionName"], litesortie.Expiry.$date.$numberLong);
918+
setWorldStateExpiry(parseInt(litesortie.Expiry.$date.$numberLong));
919+
setDatum("litesortie-header", osdict["/Lotus/Language/WorldStateWindow/LiteSortieMissionName"], parseInt(litesortie.Expiry.$date.$numberLong));
920920
document.getElementById("litesortie-header").innerHTML += " ";
921921
document.getElementById("litesortie-header").appendChild(createCompletionToggle(litesortie._id.$oid));
922922
const mission_names = [];
@@ -945,8 +945,8 @@ function updateKinePage()
945945
async function updateDarvosDeal()
946946
{
947947
window.dailyDeal = window.worldState.DailyDeals.find(x => Date.now() >= parseInt(x.Activation.$date.$numberLong) && Date.now() < parseInt(x.Expiry.$date.$numberLong));
948-
setDatum("darvo-header", "Darvo's Deal", window.dailyDeal.Expiry.$date.$numberLong);
949-
setWorldStateExpiry(window.dailyDeal.Expiry.$date.$numberLong);
948+
setDatum("darvo-header", "Darvo's Deal", parseInt(window.dailyDeal.Expiry.$date.$numberLong));
949+
setWorldStateExpiry(parseInt(window.dailyDeal.Expiry.$date.$numberLong));
950950
const item_data = await getItemDataPromise(window.dailyDeal.StoreItem);
951951
await dicts_promise;
952952
document.getElementById("darvo-item").textContent = dict[item_data.name];
@@ -976,8 +976,8 @@ async function updateBaro()
976976
document.getElementById("baro-soon").classList.add("d-none");
977977
document.getElementById("baro-now").classList.remove("d-none");
978978

979-
setWorldStateExpiry(window.worldState.VoidTraders[0].Expiry.$date.$numberLong);
980-
setDatum("baro-header", "Baro Ki'Teer", window.worldState.VoidTraders[0].Expiry.$date.$numberLong);
979+
setWorldStateExpiry(parseInt(window.worldState.VoidTraders[0].Expiry.$date.$numberLong));
980+
setDatum("baro-header", "Baro Ki'Teer", parseInt(window.worldState.VoidTraders[0].Expiry.$date.$numberLong));
981981

982982
for (const item of window.worldState.VoidTraders[0].Manifest)
983983
{
@@ -1044,8 +1044,8 @@ async function updateBaro()
10441044
document.getElementById("baro-soon").classList.remove("d-none");
10451045
document.getElementById("baro-now").classList.add("d-none");
10461046

1047-
setWorldStateExpiry(window.worldState.VoidTraders[0].Activation.$date.$numberLong);
1048-
setDatum("baro-header", "Baro Ki'Teer", window.worldState.VoidTraders[0].Activation.$date.$numberLong);
1047+
setWorldStateExpiry(parseInt(window.worldState.VoidTraders[0].Activation.$date.$numberLong));
1048+
setDatum("baro-header", "Baro Ki'Teer", parseInt(window.worldState.VoidTraders[0].Activation.$date.$numberLong));
10491049

10501050
window.last_baro_expiry = "69";
10511051
}
@@ -1091,7 +1091,7 @@ async function updateAlerts()
10911091
}
10921092
span.innerHTML += " (" + alert.MissionInfo.minEnemyLevel + "-" + alert.MissionInfo.maxEnemyLevel + ") @ "+ dict[ExportRegions[alert.MissionInfo.location].name] + ", " + dict[ExportRegions[alert.MissionInfo.location].systemName] + " ";
10931093
span.appendChild(createExpiryBadge(alert.Expiry.$date.$numberLong));
1094-
setWorldStateExpiry(alert.Expiry.$date.$numberLong);
1094+
setWorldStateExpiry(parseInt(alert.Expiry.$date.$numberLong));
10951095
span.innerHTML += " ";
10961096
span.appendChild(createCompletionToggle(alert._id.$oid));
10971097
block.appendChild(span);
@@ -1266,7 +1266,7 @@ function updateCircuit()
12661266
}
12671267
dict_promise.then(updateCircuit);
12681268

1269-
function loadScriptPromise(src)
1269+
function loadScriptPromise(src: string): Promise<any>
12701270
{
12711271
return new Promise((resolve, reject) =>
12721272
{
@@ -1279,7 +1279,7 @@ function loadScriptPromise(src)
12791279
}
12801280

12811281
const item_data_promises = {};
1282-
function getItemDataPromise(uniqueName)
1282+
function getItemDataPromise(uniqueName: string): Promise<any>
12831283
{
12841284
uniqueName = uniqueName.split("/Lotus/StoreItems/").join("/Lotus/");
12851285
if (!item_data_promises[uniqueName])
@@ -1289,7 +1289,7 @@ function getItemDataPromise(uniqueName)
12891289
return item_data_promises[uniqueName];
12901290
}
12911291

1292-
async function getItemNamePromise(uniqueName)
1292+
async function getItemNamePromise(uniqueName: string): Promise<string>
12931293
{
12941294
try
12951295
{
@@ -1313,13 +1313,13 @@ async function getItemNamePromise(uniqueName)
13131313
}
13141314
}
13151315

1316-
function isOidMarkedAsCompleted(oid)
1316+
function isOidMarkedAsCompleted(oid: string): boolean
13171317
{
13181318
const arr = JSON.parse(localStorage.getItem("oids_completed") ?? "[]");
13191319
return arr.findIndex(x => x == oid) != -1;
13201320
}
13211321

1322-
function toggleOidCompletion(oid)
1322+
function toggleOidCompletion(oid: string): void
13231323
{
13241324
const arr = JSON.parse(localStorage.getItem("oids_completed") ?? "[]");
13251325
const index = arr.findIndex(x => x == oid);
@@ -1334,12 +1334,12 @@ function toggleOidCompletion(oid)
13341334
localStorage.setItem("oids_completed", JSON.stringify(arr));
13351335
}
13361336

1337-
function createCompletionToggle(oid)
1337+
function createCompletionToggle(oid: string): HTMLAnchorElement
13381338
{
13391339
let what = "completed";
1340-
if (oid.substr(0, 5) == "kahlb")
1340+
if (oid.substring(0, 5) == "kahlb")
13411341
{
1342-
what += " (Bonus Objective #" + oid.substr(5, 1) + ")";
1342+
what += " (Bonus Objective #" + oid.substring(5, 6) + ")";
13431343
}
13441344

13451345
const a = document.createElement("a");
@@ -1442,7 +1442,7 @@ function updateInvasions()
14421442
});
14431443
}
14441444

1445-
function setFissuresExpiry(expiry)
1445+
function setFissuresExpiry(expiry: number): void
14461446
{
14471447
if (!window.refresh_fissures_at || window.refresh_fissures_at > expiry)
14481448
{
@@ -1611,11 +1611,11 @@ setInterval(function()
16111611
{
16121612
for (const elm of document.querySelectorAll(".badge[data-expiry]"))
16131613
{
1614-
elm.textContent = formatExpiry(elm.getAttribute("data-expiry"));
1614+
elm.textContent = formatExpiry(parseInt(elm.getAttribute("data-expiry")));
16151615
}
16161616
for (const elm of document.querySelectorAll(".badge[data-activation]"))
16171617
{
1618-
elm.textContent = formatActivation(elm.getAttribute("data-activation"));
1618+
elm.textContent = formatActivation(parseInt(elm.getAttribute("data-activation")));
16191619
}
16201620
}, 100);
16211621

@@ -1647,7 +1647,7 @@ setInterval(function()
16471647
}
16481648
}, 500);
16491649

1650-
function refreshCollapseStatus(elm)
1650+
function refreshCollapseStatus(elm: HTMLElement): void
16511651
{
16521652
const engaged = localStorage.getItem("live.collapse." + elm.getAttribute("data-collapse-toggle"));
16531653
const span = document.createElement("span");
@@ -1684,7 +1684,7 @@ document.querySelectorAll<HTMLSpanElement>("[data-collapse-toggle]").forEach(elm
16841684
};
16851685
});
16861686

1687-
function sendNotification(text)
1687+
function sendNotification(text: string): void
16881688
{
16891689
const toast = document.createElement("div");
16901690
toast.className = "toast align-items-center text-bg-primary border-0";
@@ -1707,7 +1707,7 @@ function sendNotification(text)
17071707
}
17081708
}
17091709

1710-
function refreshNotifStatus(elm)
1710+
function refreshNotifStatus(elm: HTMLElement): void
17111711
{
17121712
const enabled = localStorage.getItem("live.notif." + elm.getAttribute("data-notif-toggle"));
17131713
const span = document.createElement("span");
@@ -1743,4 +1743,4 @@ document.querySelectorAll<HTMLAnchorElement>("[data-notif-toggle]").forEach(elm
17431743
};
17441744
});
17451745

1746-
document.querySelectorAll(".vq-abbr").forEach(elm => addTooltip(elm, "Voidplume Quills"));
1746+
document.querySelectorAll<HTMLElement>(".vq-abbr").forEach(elm => addTooltip(elm, "Voidplume Quills"));

0 commit comments

Comments
 (0)