A few days ago, David Heinemeier Hansson announced that Turbo 8 is dropping TypeScript . I'm okay with that because I don't even know what Turbo 8 is. However, over the past few years, some frontend programmers have tried to sell me the idea that "TypeScript is useless, just use tests". I think people with such opinions either don't care about code quality or simply don't know what TypeScript is. Here, I will explain why you should use TypeScript.

Can wasm manipulate the DOM yet?

TehPers
link
fedilink
English
41Y

It can with some glue code that you better be writing in TypeScript if you care about code quality.

(As far as I know, it can’t manipulate the DOM directly. Maybe things changed in the past couple months since I checked, but I doubt it.)

WASM allows arbitrary code execution in an environment that doesn’t include the DOM… however it can communicate with the page where the DOM is available, and it’s trivial to setup an abstraction layer that gives you the full suite of DOM manipulation tools in your WASM space. Libraries for WASM development generally provide that for you.

For example here’s SwiftWASM:

let document = JSObject.global.document

var divElement = document.createElement("div")
divElement.innerText = "Hello, world"
_ = document.body.appendChild(divElement)

It’s pretty much exactly the same as JavaScript, except you nee to use JSObject to access the document class (Swift can do globals, but they are generally avoided) and swift also presents a compiler warning if you execute a function (like appendChild) without doing anything with the result. Assigning it to a dummy “underscore” variable is the operator in Swift to tell the compiler you don’t want the output.

Create a post

All things programming and coding related. Subcommunity of Technology.


This community’s icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.

  • 1 user online
  • 7 users / day
  • 7 users / week
  • 14 users / month
  • 121 users / 6 months
  • 1 subscriber
  • 296 Posts
  • 2.15K Comments
  • Modlog