If you don’t already know what a .d.ts file is, I recommend reading my other post on the topic. Writing and managing types for a Typescript project is a cumbersome issue, and one that is often handled differently from project to project. A common pattern that has evolved is to “place types where they are […]
Category: Typescript
How to get started with Typescript
So, you’ve decided that Javascript is the language you want to pursue and learn. Upon googling “how to learn javascript” you quickly start seeing “Typescript” appearing again and again. Intrigued you wonder “what is Typescript? Is that something I need to know? Should I learn that instead?”. A bit worried you continue your quest for […]
How to work with union types that can be undefined
Ever struggled with figuring out how to deal with undefined? Or spent a good cup of coffee (and a half) to stop the Typescript compiler from screaming at you? In Typescript we often come across values that can have multiple values, called union types, and in some cases one of those values is undefined. If […]
“I love Typescript, but I hate the configuration”
Back upright, posture checked, fingers have just been cracked, you’ve got some good music playing and you’re ready to sit down and start coding on your new cool idea. Whilst ideas begin to unfold in your mind and you’re about to burst with creativity you envision “hey, this would be a cool opportunity to get […]
How to manage consistent types using extract
As we start unfolding Typescript and start to maintain an ever-increasing amount of types in our codebase, we might want to start doing things smarter at some point. I’m a very pragmatic person and that makes me subscribe to the idea of DRY; especially when it comes to managing types. I really do not want […]
Enabling ESM with TS, without the headaches
Are you wanting to get on the latest trend and replace CommonJS (CJS) with EcmaScript Modules (ESM)? Maybe you’re forced to upgrade because the libraries you’re using are. Maybe you’ve even tried, with the aid of ChatGPT but still came up empty-handed? Or maybe you’re just attempting this migration because you’re upgrading node and decided […]
How to properly use a .d.ts files
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 […]
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 JS-to-TS Expedition: Full Migration Showdown or Partial Progress Party?
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 […]