Member-only story
Typescript CLI— Todo List
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.
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)": ""}`);
}
}