Skip to content

Commit 023aaad

Browse files
committed
remove any
1 parent a59cb52 commit 023aaad

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

src/main.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export type PluginState = {
1212
[index: number]: {
1313
hp?: number;
1414
stress?: number;
15-
uses?: number[];
16-
countdown?: number[];
15+
uses?: { [key: string]: number };
16+
countdown?: { [key: string]: number}
1717
};
1818
};
1919
};
@@ -77,7 +77,7 @@ export default class BeastVault extends Plugin {
7777
}
7878
const newLibrary: Adversary[] = [];
7979
await walkFolder(folder, async (file) => {
80-
let content: any;
80+
let content: Adversary | Adversary[];
8181

8282
if (file.extension == 'json') {
8383
content = JSON.parse(await this.app.vault.read(file));
@@ -279,24 +279,26 @@ export default class BeastVault extends Plugin {
279279
}
280280

281281
updateCard(keys: (string | number)[], value: string | number) {
282-
let data: Record<any, any> = this.state.cards;
282+
type Data = { [key: string]: Data | number | string };
283+
let data: Data = this.state.cards;
283284
const keysCopy = [...keys];
284285
const lastKey = keysCopy.pop()!;
285286
for (const key of keysCopy) {
286287
if (!data[key]) data[key] = {};
287-
data = data[key]
288+
data = data[key] as Data;
288289
}
289290
data[lastKey] = value;
290291
this.updateState();
291292
}
292293

293294
getCardState(keys: (string | number)[]): number | undefined {
294-
let data: any = this.state.cards;
295+
type Data = { [key: string]: Data | string | number }
296+
let data: Data = this.state.cards;
295297
for (const key of keys) {
296-
if (data[key] == null) return undefined;
297-
data = data[key]
298+
if (!data[key]) return undefined;
299+
data = data[key] as Data;
298300
}
299-
return data;
301+
return data as any;
300302
}
301303
}
302304

src/ui.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,24 +220,26 @@ export class AdversaryCard extends MarkdownRenderChild {
220220
}
221221
}
222222

223-
let hordeSize: any;
223+
let hordeSize: HTMLElement | null = null;
224+
let updateHordeSize: (() => void) | null = null;
224225
const match = this.adv.type?.match(/^horde\s+\((\d+)\/hp\)$/i);
225226
if (match && this.adv.hp > 0) {
226227
hordeSize = statBar.createSpan({ cls: "bv-muted" });
227-
hordeSize.update = () => {
228+
updateHordeSize = () => {
229+
if (hordeSize == null) return;
228230
const size = parseInt(match[1]);
229231
const hp = this.plugin.getCardState([this.adv.id, index, 'hp']) ?? 0;
230232
const currentHP = this.adv.hp - hp;
231-
hordeSize!.innerText = `Horde size: ${size * currentHP}`;
233+
hordeSize.innerText = `Horde size: ${size * currentHP}`;
232234
};
233-
hordeSize.update();
235+
updateHordeSize();
234236
statBar.addEventListener('input', (event) => {
235237
if (!hpSlots.contains(event.target as HTMLInputElement)) return;
236-
hordeSize?.update();
238+
updateHordeSize?.();
237239
})
238240
}
239241

240-
const slotMarker = (x: number) => (event: any) => {
242+
const slotMarker = (x: number) => (event: MouseEvent) => {
241243
const slots = event.altKey ? hpSlots.toReversed() : hpSlots;
242244
let toMark = x;
243245
let marked = 0;
@@ -250,7 +252,7 @@ export class AdversaryCard extends MarkdownRenderChild {
250252
if (slot.checked) marked++;
251253
}
252254
this.plugin.updateCard([this.adv.id, index, 'hp'], marked)
253-
hordeSize?.update();
255+
updateHordeSize?.();
254256
};
255257

256258
minor?.addEventListener('click', slotMarker(1));

0 commit comments

Comments
 (0)