List of article summaries
How to write an ESLint plugin in TypeScript
I use NestJS at my day job. It’s a complicated framework sometimes and there are lots of things that devs “just have to remember” or there will be bugs in your application that you won’t see until runtime.
I wanted to remove this cognitive load from NestJS engineers so that they can focus on valuable work instead. I wrote an ESLint plugin to alert developers directly in their IDE or editor when these common issues exist - (Available on NPM) https://www.npmjs.com/package/@darraghor/eslint-plugin-nestjs-typed
Here is what I learned about writing ESLint plugins in typescript for typescript while building the plugin.
Create an only ever true boolean type in typescript
Integrating with an API where a boolean can only be undefined or true I needed to type it. It’s easy enough but I just wanted to jot it down in case any one else needs this in the future.
How to change the type of output for a property filter in typescript
If you have an iterable filter on a property in typescript you might have a slightly different model coming out of the filter based on the filter condition.
By setting the types correctly you can potentially save having to add manual typing hints in whatever follows the filter.
It’s easier to show this with code so see below!
Thanks to one of my colleagues for suggesting this one in a code review.
Copying missing files during a typescript build on deploy
If you build your nodeJS project using typescript, it’s important to know that the typescript compiler
tsc will only include files that are
If you have an issue where you deploy or build a typescript project and you get a file not found issue or similar, it’s probably because you missed that typescript does not process these kinds of files for you.
If you need to include files like XML (
.xml) or images in your typescript project build output, you will have to copy them manually before or after the build process.
This is one way to copy assets in a typescript build.
Five quick jest and typescript tips
I’ve been working with jest every day for the past month or so. I had to learn a few tricks as I went. I was mocking, using async, upgrading versions and working in vscode. Here are five things I learned.
TSLint is deprecated: how to upgrade to ESlint
I recently upgraded my production typescript project from TSLint to ESLint. Here are the steps and and why I migrated manually.
How to setup TSLint and Prettier for TypeScript projects
UPDATE 10/10/2020: Tslint is being deprecated. You should consider changing to Eslint. I have a guide for that here: TSLint is deprecated: How to upgrade to ESlint.
TSLint will help us identify potential issues in our code by examining how we use language features.
Prettier will format code consistently but needs some configuration to work with TSLint.
Together they make code-reviews easier and faster because if you run both of them you will identify many common code review errors before pushing your code.
There needs to be some configuration to have both work together. Here is my cheatsheet for setting this up on a project.
How I configure jest on a typescript Node.js application
Here is some of the jest configuration I have for a Node.js application in typescript that builds on a CI system.
Typescript error "does not satisfy the constraint new" when using InstanceType in typegoose
If you get an error when trying to use InstanceType from typegoose as a parameter to a method in typescript make sure you are importing it from typegoose explicitly.
How to await async functions in specific sequence using typescript
I was posting messages to a slack webhook recently and I wanted to post a list of messages in the correct order. I had to await each one before calling the next. I tried a few different methods but only one worked the way I expected it to.
How to log full objects in winston (hint... Use meta data)
I’m exploring the Azure Devops API at the moment and I find logging out the API responses is far better than trying to understand the documentation.
It seems super obvious now but it took me some messing around to figure out that you need to supply the object as meta data to the winston logger!
How to check bitwise mask in typescript
I’m currently building a little app that talks to the Azure Devops API and I had to check a bitwise operator in typescript today. I hardly ever do this these days so it took me a bit of time to get it right!