Member-only story

Typescript CLI— Todo List

Tomas Svojanovsky
4 min readJul 31, 2023

--

Welcome to the world of building CLI (Command Line Interface) tools with a delightful user interface!

But that’s not all! To make our CLI tool even more user-friendly and versatile, we’ll be integrating a JSON database called lowdb, which allows us to store and manage data. This combination of TypeScript and lowdb will enable us to create robust, interactive, and efficient CLI tools.

Photo by Pankaj Patel on Unsplash

Add Typescript

npm init -y
npm install typescript

package.json

Add this line to package.json. Because of the module option, we need to include the js suffix in imports.

"type": "module"

tsconfig.json

{
"compilerOptions": {
"target": "ES2022",
"outDir": "./dist",
"rootDir": "./src",
"module": "Node16",
}
}

Todo item

export class TodoItem {
constructor(public id: number, public task: string, public complete: boolean = false) {}

toString(): string {
return `Id: ${this.id}, Task: ${this.task}, Complete: ${this.complete ? "Done" : "In progress"}`;
}

printDetails(): void {
console.log(`${this.id}\t${this.task} ${this.complete ? "\t(complete)": ""}`);
}
}

TodoCollection.ts

--

--

Tomas Svojanovsky
Tomas Svojanovsky

Written by Tomas Svojanovsky

I'm a full-stack developer. Programming isn't just my job but also my hobby. I like developing seamless user experiences and working on server-side complexities

No responses yet