DEV Community

Bryce Seefieldt
Bryce Seefieldt

Posted on

TypeScript in WSL

This week I got a chance to add some functionality to a new project written with Typescript. The goal was to introduce functionality to use TOML files in order to provide config details at runtime, with the switch -c or --config overriding additional command line switches when executing the program and instead parsing the provided .toml file.

While TS is not new territory for me, the particular program I worked on exposed me to a few new concepts and present some interesting challenges. The til-to-html project utilized a runtime build tool, Bun, as well as Unzip, a tool provided by Ubuntu. This required that I work in Linux. To do this on my Windows machine, I setup a new Windows Subsystem for Linux (WSL) environment. This was straightforward to install, as were the Bun and Unzip installs. However being a brand new WSL environment it took some time to get the required tools functioning properly. The main solution required to make unzip execute when needed was to add the /usr/bin/ directory to PATH in the ~/.bashrc file. This got me to a place where I could build and execute a local version of the til-to-html program.
After this, it was clear sailing for the most part. First by adding some logic within the exisiting argument parser to recognize -c or --config command line arguments. The great news was that TypeScript offers a toml module which made easy work of parsing the TOML file. Literally as simple as using toml.parse() on the contents of the opened file. This provides a variable containing all arguments defined in the file, accesible as .version, .help, etc. This made light work of passing all arguments included into the TOML file back into the exisiting code and continuing execution as if the arguments were passed by command line. Good fun and an excellent challenge for the week.

Top comments (0)