AssemblyScript compiles TypeScript to WebAssembly

AssemblyScript brings fast, portable WebAssembly binaries within easy reach of TypeScript developers, although only a subset of TypeScript is supported

AssemblyScript compiles TypeScript to WebAssembly

A project called AssemblyScript is providing a bridge between WebAssembly, the portable binary code format designed to make web applications run faster, and TypeScript, Microsoft’s typed JavaScript superset. 

A subset of TypeScript itself, AssemblyScript gives developers with a background in TypeScript and standard JavaScript APIs a way to compile to WebAssembly. The project is currently characterized as being in a beta state of development by its main developer, Daniel Wirtz. “My aim [with AssemblyScript] is to create something simple, i.e. something you can ‘npm install’ to compile to WebAssembly instead of installing and setting up more complex tool chains,” he said.

What AssemblyScript does is rewire the TypeScript compiler API to the BInaryen compiler back end, which is is able to produce WebAssembly binaries. Rather than re-implementing TypeScript as closely as possible at the expense of performance, AssemblyScript attempts to support features as closely as is reasonable without supporting certain dynamic constructs. AssemblyScript programs are valid TypeScript syntactically although not necessarily semantically. 

AssemblyScript has a few special requirements. For example, types must be annotated to avoid unwanted implicit conversions. Also, optional functional parameters require an initializer expression. Union types, except classType | null, any, and undefined are not supported by design. 

Project documentation describes AssemblyScript as new and ambitious, developed by one person [Wirtz] and occasional contributors. Bugs and breaking changes are to be expected. Wirtz plans to support more of TypeScript while waiting on additional WebAssembly capabilities for garbage collection and exception handling. “The ultimate goal is to be able to compile the AssemblyScript compiler to WebAssembly using itself, in a browser, without using clever workarounds.”

Wirtz is pleased with WebAssembly’s binary format. But he sees it creating a challenge for developers in that its intended support of multiple languages will require proficiency in and development environments for different languages.

Copyright © 2017 IDG Communications, Inc.

InfoWorld Technology of the Year Awards 2023. Now open for entries!