about summary refs log tree commit diff
path: root/kittybox-rs/javascript
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2022-09-29 22:39:28 +0300
committerVika <vika@fireburn.ru>2022-09-29 22:39:28 +0300
commitb7d4e5c4686bc8aac41d832567190002542a1743 (patch)
tree6a42a990fbb06057a64de5f68175f94c3637c2c7 /kittybox-rs/javascript
parentb3508ccb146648950ed392b517d12354203c4347 (diff)
downloadkittybox-b7d4e5c4686bc8aac41d832567190002542a1743.tar.zst
companion-lite: port to TypeScript
Diffstat (limited to 'kittybox-rs/javascript')
-rw-r--r--kittybox-rs/javascript/src/indieauth.ts15
-rw-r--r--kittybox-rs/javascript/src/lib.ts3
2 files changed, 13 insertions, 5 deletions
diff --git a/kittybox-rs/javascript/src/indieauth.ts b/kittybox-rs/javascript/src/indieauth.ts
index ef314e9..01732b7 100644
--- a/kittybox-rs/javascript/src/indieauth.ts
+++ b/kittybox-rs/javascript/src/indieauth.ts
@@ -1,3 +1,5 @@
+import { unreachable } from "./lib.js";
+
 const WEBAUTHN_TIMEOUT = 60 * 1000;
 
 interface KittyboxWebauthnPreRegistrationData {
@@ -69,16 +71,19 @@ export async function submit_handler(e: SubmitEvent) {
     const form = e.target as HTMLFormElement;
 
     let scopes: Array<string>;
-    if (form.elements.namedItem("scope") === undefined) {
+    let scope_elem = form.elements.namedItem("scope");
+    if (scope_elem == null) {
       scopes = []
-    } else if (form.elements.namedItem("scope") instanceof Node) {
-      scopes = ([form.elements.namedItem("scope")] as Array<HTMLInputElement>)
+    } else if (scope_elem instanceof Element) {
+      scopes = ([scope_elem] as Array<HTMLInputElement>)
         .filter((e: HTMLInputElement) => e.checked)
         .map((e: HTMLInputElement) => e.value);
-    } else {
-      scopes = (Array.from(form.elements.namedItem("scope") as RadioNodeList) as Array<HTMLInputElement>)
+    } else if (scope_elem instanceof RadioNodeList) {
+      scopes = (Array.from(scope_elem) as Array<HTMLInputElement>)
         .filter((e: HTMLInputElement) => e.checked)
         .map((e: HTMLInputElement) => e.value);
+    } else {
+      unreachable("HTMLFormControlsCollection returned something that's not null, Element or RadioNodeList")
     }
 
     const authorization_request = {
diff --git a/kittybox-rs/javascript/src/lib.ts b/kittybox-rs/javascript/src/lib.ts
new file mode 100644
index 0000000..38ba65b
--- /dev/null
+++ b/kittybox-rs/javascript/src/lib.ts
@@ -0,0 +1,3 @@
+export function unreachable(msg: string): never {
+  throw new Error(msg);
+}