return types in typescript
This commit is contained in:
parent
42089136e1
commit
510906437f
3 changed files with 22 additions and 22 deletions
|
@ -10,14 +10,14 @@ let showSingles = false;
|
|||
|
||||
|
||||
function fillSets(): [Set<string>, Set<string>] {
|
||||
function checkedValues(boxes: Boxes) {
|
||||
function checkedValues(boxes: Boxes): Set<string> {
|
||||
return new Set([...boxes].filter(b => b.checked).map(b => b.value));
|
||||
}
|
||||
|
||||
return [checkedValues(reqBoxes), checkedValues(excBoxes)];
|
||||
}
|
||||
|
||||
function updateItems() {
|
||||
function updateItems(): void {
|
||||
const [reqTags, excTags] = fillSets();
|
||||
const anyReq = reqTags.size > 0;
|
||||
|
||||
|
@ -37,7 +37,7 @@ function updateItems() {
|
|||
if (marker !== null) marker.hidden = hideMarker;
|
||||
}
|
||||
|
||||
function disp(pfx: string, tags: Iterable<string>) {
|
||||
function disp(pfx: string, tags: Iterable<string>): string {
|
||||
return [...tags].map(x => pfx + x).join('\u2003'); // em space
|
||||
}
|
||||
const plus = disp('+\u2009', reqTags); // thin space
|
||||
|
@ -46,12 +46,12 @@ function updateItems() {
|
|||
`${plus}\u2003${minus}`.trim();
|
||||
}
|
||||
|
||||
function update() {
|
||||
function update(): void {
|
||||
updateItems();
|
||||
history.pushState(null, "", makeFragment());
|
||||
}
|
||||
|
||||
function converseId(id: string) {
|
||||
function converseId(id: string): string {
|
||||
if (id.match(/^require/)) {
|
||||
return id.replace('require', 'exclude');
|
||||
} else {
|
||||
|
@ -59,7 +59,7 @@ function converseId(id: string) {
|
|||
}
|
||||
}
|
||||
|
||||
function toggle(checkbox: HTMLInputElement) {
|
||||
function toggle(checkbox: HTMLInputElement): void {
|
||||
if (checkbox.checked) {
|
||||
const converse = document.getElementById(converseId(checkbox.id)) as HTMLInputElement;
|
||||
converse.checked = false;
|
||||
|
@ -68,17 +68,17 @@ function toggle(checkbox: HTMLInputElement) {
|
|||
}
|
||||
|
||||
|
||||
function clearForm() {
|
||||
function clearForm(): void {
|
||||
allBoxes.forEach(b => b.checked = b.defaultChecked);
|
||||
}
|
||||
|
||||
function clear(e: Event) {
|
||||
function clear(e: Event): void {
|
||||
clearForm();
|
||||
update();
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function toggleSingles(e: Event) {
|
||||
function toggleSingles(e: Event): void {
|
||||
showSingles = !showSingles;
|
||||
|
||||
const elems = Array.from(document.querySelectorAll('.filterlist li')) as HTMLElement[];
|
||||
|
@ -94,7 +94,7 @@ function toggleSingles(e: Event) {
|
|||
}
|
||||
|
||||
|
||||
function makeFragment() {
|
||||
function makeFragment(): string {
|
||||
const allBoxesArr = Array.from(allBoxes);
|
||||
const ids = allBoxesArr.filter(b => b.checked).map(b => b.id);
|
||||
if (ids.length == 0) {
|
||||
|
@ -107,7 +107,7 @@ function makeFragment() {
|
|||
}
|
||||
|
||||
|
||||
type Shortcuts = { [short: string]: Set<string> };
|
||||
type Shortcuts = Record<string, Set<string>>;
|
||||
const shortcuts: Shortcuts = {
|
||||
summary: new Set(['require_artsummary']),
|
||||
colourexamples: new Set(['require_colourexample']),
|
||||
|
@ -120,7 +120,7 @@ const shortcuts: Shortcuts = {
|
|||
kesi: new Set(['require_kesi']),
|
||||
};
|
||||
|
||||
function useFragment() {
|
||||
function useFragment(): void {
|
||||
const frag = decodeURIComponent(location.hash).replace(/^#/, '');
|
||||
const details = document.getElementById('filters-details') as HTMLDetailsElement;
|
||||
const fromShortcut = shortcuts[frag];
|
||||
|
@ -145,8 +145,8 @@ function useFragment() {
|
|||
}
|
||||
|
||||
|
||||
function sortFilters(cmp: (a: Node, b: Node) => number) {
|
||||
function sort1(id: string) {
|
||||
function sortFilters(cmp: (a: Node, b: Node) => number): void {
|
||||
function sort1(id: string): void {
|
||||
const elt = document.getElementById(id);
|
||||
if (elt === null) return;
|
||||
|
||||
|
@ -162,7 +162,7 @@ function sortFilters(cmp: (a: Node, b: Node) => number) {
|
|||
sort1('exclude');
|
||||
}
|
||||
|
||||
function sortFiltersAlpha(e: Event) {
|
||||
function sortFiltersAlpha(e: Event): void {
|
||||
function getName(node: Node): string {
|
||||
if (node instanceof Element) {
|
||||
return node.getElementsByTagName('input')[0]?.value ?? '';
|
||||
|
@ -174,7 +174,7 @@ function sortFiltersAlpha(e: Event) {
|
|||
e.preventDefault();
|
||||
}
|
||||
|
||||
function sortFiltersUses(e: Event) {
|
||||
function sortFiltersUses(e: Event): void {
|
||||
function getUses(node: Node): number {
|
||||
if (node instanceof Element) {
|
||||
const countStr = node.getElementsByTagName('label')[0]?.dataset.count;
|
||||
|
@ -188,7 +188,7 @@ function sortFiltersUses(e: Event) {
|
|||
}
|
||||
|
||||
|
||||
function setup() {
|
||||
function setup(): void {
|
||||
function inputs(id: string): Boxes {
|
||||
const iter = document.getElementById(id)!.getElementsByTagName('input');
|
||||
return new Set(Array.from(iter));
|
||||
|
@ -216,7 +216,7 @@ function setup() {
|
|||
|
||||
allBoxes.forEach(b => b.addEventListener('change', () => toggle(b)));
|
||||
|
||||
function addClick(id: string, f: (e: Event) => void) {
|
||||
function addClick(id: string, f: (e: Event) => void): void {
|
||||
document.getElementById(id)!.addEventListener('click', f);
|
||||
}
|
||||
addClick('clear', clear);
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
const nsfwOk = 'nsfw-ok';
|
||||
const dialog = document.getElementById('nsfw-dialog')! as HTMLDialogElement;
|
||||
|
||||
function yes() {
|
||||
function yes(): void {
|
||||
localStorage.setItem(nsfwOk, '1');
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
function setup() {
|
||||
function setup(): void {
|
||||
if (!localStorage.getItem(nsfwOk)) {
|
||||
(dialog.querySelector('#nsfw-yes') as HTMLElement).onclick = yes;
|
||||
// nsfw-no is a normal link
|
||||
|
|
|
@ -28,7 +28,7 @@ function setImage(id: string, src: string, href: string,
|
|||
|
||||
if (curCw && !coverNew) {
|
||||
// keep old cover until load
|
||||
function removeCover() { setTimeout(() => openCW(null, curCw!), 100); }
|
||||
function removeCover(): void { setTimeout(() => openCW(null, curCw!), 100); }
|
||||
mainimg.addEventListener('load', removeCover, {once: true});
|
||||
} else if (coverNew) {
|
||||
// place new cover
|
||||
|
@ -82,7 +82,7 @@ function useFragment(firstLoad = false): void {
|
|||
}
|
||||
}
|
||||
|
||||
function setup() {
|
||||
function setup(): void {
|
||||
mainfig = document.getElementById('mainfig')!;
|
||||
mainimg = document.getElementById('mainimg') as HTMLImageElement;
|
||||
mainlink = document.getElementById('mainlink') as HTMLAnchorElement;
|
||||
|
|
Loading…
Add table
Reference in a new issue