If you’ve ever need a global type to be available or perhaps already have a few, then There are several cases in Node where we may want to extend interfaces, a common such example is when using the library passport that often recommends appending a user object to our express Request object. Using Typescript, this […]
Author: Martin Aarhus Gregersen
Taking the ‘Patch’ Out of Monkeypatching: Adding Properties in TypeScript
Let’s dive in. It’s a common scenario. You’re coding away in TypeScript, enjoying the safety net of static types. Then, you hit a snag. You need to attach a new property to an existing object, and TypeScript, in all its type-safe glory, is telling you, “Nope, sorry, that’s not going to happen.” In your case, […]
How to fix “Uncaught ReferenceError: process is not defined” error
Ever run into this dreaded issue when working with Javascript or – preferably – Typescript?Nothing is more frustrating than happily coding away, deciding you want to increase the security abstraction layer a bit – or perhaps you subscribe to the 12 Factor App – only to get met with this error. Thankfully, you’ve come to […]
The dreaded JS-to-TS Migration: Partial progress or full migration?
I write a lot about Typescript. I write a lot about why I think it’s better than Javascript. And perhaps I’ve convinced you too! Maybe you want to start converting some JS projects to TS and see what the fuzz is all about. The only thing blocking you is… How the hell do I get […]
Why pure functions are just better in TS
When writing code in TS there are various design choices and patterns that we use, some occurring on purpose and others just happening with little or no thought. One such example is “pure functions” a concept from Javascript that is in my opinion, even more important in Typescript. Pure functions are a simple concept that […]
TS Debugging that doesn’t suck
Unfortunately, at some point or another you are going to create a bug in your system. The larger it grows the more likely it is that you will create that bug. Or an exception! Lean more on how to deal with those here. So what do we do about it? Well, we need to arm […]
How to handle exceptions in Typescript
In Typescript, exceptions can be a bit weird. This is especially true if you’re writing library code or a VSCode plugin. Because almost surely you’ll want to output nice and custom error messages to the end user. Typescript doesn’t allow for a try/catch block to catch type errors, like it would for runtime errors. So […]
Switching from JS to TS as an experienced programmer
Few programmers start their journey with Typescript. There’s a wide variety of languages we could start with and while it isn’t all that important, a common denominator despite how we learn the web, is Javascript. Most developers encounter javascript at some point or another, as part of making their websites interactive, adding a little bit […]
3 libraries for how to best setup Typescript compilation with Javascript rerendering
This post was updated in May 2024, to include a new contender with fewer tools as a potential winner as my personal preference. For Javascript, we are lucky to have an extremely popular library titled nodemon. For Typescript, we’re not quite as lucky. But we do have a few options! In this short article, I’ll […]
How to write a function with a conditionally required parameter
Functions are the bread and butter of Javascript. It leans more strongly into a functional programming paradigm than any modern language today. But functions can be weird! Then, on top of that, let’s add the added layer of complexity that is Typescript. How do we start defining types for weird functions? What if I wanted […]