Typescripten — generating type-safe JavaScript bindings for emscripten


WebAssembly has become a very popular target platform for C++ developers. Thanks to emscripten, porting native applications to WebAssembly is easy — as long as the application only uses the browser as a display and input device. However, emscripten does not provide type-safe wrappers to the standard JavaScript APIs such as the DOM manipulation API, let alone any other JavaScript API provided by existing web applications.

Open source tool "typescripten" has been built on top of three powerful technologies to close this gap. It uses TypeScript interface definition files and the TypeScript compiler API to create type-safe C++ wrappers based on emscripten. TypeScript already has to interface definition files for over 7000 JavaScript libraries that you can now use safely from C++.

Think-cell strive to design C++ wrappers such that the C++ code using them looks similar to the equivalent TypeScript or JavaScript code. However, the peculiar semantics of prototype-based Javascript and Typescript is often difficult to translate into a type-based language such as C++. Sebastian will discuss the challenges the team faced and the choices they made when designing this framework.