Enums considered harmful

January 24, 2023typescriptenum

It seems that torwards the end of 2022 the collective hivemind of the TypeScript programming world decided that enums are terrible. While I mostly agree with the premise that TypeScript enums are not good the solutions that are presented often only deal with String enums. For my work on SDL_ts I really need a solution for Numeric enums as SDL is full of them.

Read More

deno: Get the path of the current script in

In deno obtaining the path of the current script is done via the import.meta.url api:

const scriptPath = new URL(import.meta.url).pathname;

On Windows though this will return a path with unix style path seperators and a leading /:

Read More

Iterating thru an Object in JavaScript

For the longest time if I wanted to iterate thru an object in JavaScript I would write code that looked something like this:

const obj = { a: "foo", b: "bar" };
for (const key of Object.keys(obj)) {
    console.info(key, obj[key]);

Since ES2017 there is a better way of doing this using Object.entries() and destructuring:

const obj = { a: "foo", b: "bar" };
for (const [ key, value ] of Object.entries(obj)) {
    console.info(key, value);
Read More

Powered by TypeScript

June 4, 2021typescript

Over the past couple of years my career has moved more and more torwards me becoming a frontend developer. Since 2018 I've basically been a TypeScript programmer professionally and the language has really grown on me. Over the last couple of days I've had some down time so I decided now was the time to reprogram the blog in TypeScript.

The site is still a static site but the compiler is a now a custom TypeScript program. The size of the program is now considerably smaller but that isn't necessarily becuase C# was bad but rather that this is the 2nd implementation and I know what I did and did not need.

Convert TypeScript AST to JSON

January 13, 2021nodetypescript

I needed to convert a TypeScript AST (Abstract Syntax Tree) to json so that I can consume it in a C# application so I wrote a tiny node script to convert the AST to json.

Read More