From 83beef2b703444e6fb53fce0d476995437f29951 Mon Sep 17 00:00:00 2001 From: Matt Keeter Date: Thu, 18 Apr 2024 08:50:09 -0400 Subject: [PATCH] Get types from WebAssembly import (neat!) (#92) --- wasm-demo/index.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wasm-demo/index.ts b/wasm-demo/index.ts index 33234234..3b61eccc 100644 --- a/wasm-demo/index.ts +++ b/wasm-demo/index.ts @@ -6,17 +6,19 @@ import { defaultKeymap } from "@codemirror/commands"; const RENDER_SIZE = 512; async function setup() { - const fidget: any = await import("./pkg").catch(console.error); + const fidget = (await import("./pkg").catch( + console.error, + )) as typeof import("./pkg"); const draw = glInit(); function setScript(text: string) { let shape = null; let result = null; try { - shape = fidget.eval_script(text); + const shapeTree = fidget.eval_script(text); result = "Ok(..)"; const startTime = performance.now(); - shape = fidget.render(shape, RENDER_SIZE); + shape = fidget.render(shapeTree, RENDER_SIZE); const endTime = performance.now(); document.getElementById("status").textContent = `Rendered in ${endTime - startTime} ms`;