The lack of flexibility and safety in C language development has been criti- cized for a long time, causing detriments to the development cycle and software quality in the embedded systems domain. TypeScript, as an optionally-typed dynamic language, offers the flexibility and safety that developers desire. With the advancement of Ahead-of-Time (AOT) compilation technologies for TypeScript and JavaScript, it has become feasible to write embedded applications using TypeScript. Despite the availability of writing AOT compiled programs with TypeScript, implementing a compiler toolchain for this purpose requires substantial effort.
To simplify the design of languages and compilers, this paper presents a new compiler toolchain design methodology called TS−, which advocates the generation of target intermediate language code (such as C) from TypeScript rather than the construction of higher-level compiler tools and type systems on top of the intermediate language. TS− not only simplifies the design of the system but also provides developers with a quasi-native TypeScript development experience. This paper also presents Ts2Wasm, a prototype that implements TS− and allows compiling a subset of language TypeScript to WebAssembly (WASM). The tests from the repository TypeScript show that Ts2Wasm provides 3.8x as many features compared to the intermediate language (AssemblyScript). Regarding performance, Ts2Wasm offers a significant speed-up of 1.4x to 19x. Meanwhile, it imposes over 65% less memory overhead compared to Node.js in most cases.