Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript Tutorial
  • TS Exercise
  • TS Interview Questions
  • TS Cheat Sheet
  • TS Array
  • TS String
  • TS Object
  • TS Operators
  • TS Projects
  • TS Union Types
  • TS Function
  • TS Class
  • TS Generic
Open In App
Next Article:
Moment.js using with Typescript
Next article icon

Task Management App Using TypeScript

Last Updated : 22 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Task management apps help users organize their daily activities effectively. In this article, we will create a simple task management app that allows users to add and delete tasks. We’ll use HTML for structure, CSS for styling, and TypeScript for functionality to make it robust and type-safe.

What We’re Going to Create

We will build a task management app with the following features:

  • Add tasks with a description.
  • Delete tasks.
  • Store tasks in localStorage for persistence.
  • Maintain a clean and user-friendly interface.

Project Preview

Task-Manager-typescript
Task Management App

Task Management App- HTML and CSS Setup

The following code creates the structure and style for the app. It includes an input field for adding tasks, a button to submit them, and a container for displaying the task list.

HTML
<html> <head>     <style>         body {             font-family: 'Arial', sans-serif;             background-color: black;             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             margin: 0;             color: #fff;         }         .container {             background: rgba(255, 255, 255, 0.1);             padding: 2rem;             border-radius: 15px;             box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);             width: 100%;             max-width: 400px;         }         input[type="text"] {             width: calc(100% - 100px);             padding: 0.8rem;             border-radius: 8px;             border: none;             outline: none;             font-size: 1rem;             margin-right: 1rem;             box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);         }         button {             box-sizing: border-box;             padding: 0.8rem 1rem;             border-radius: 8px;             border: none;             background: #ff6b6b;             color: #fff;             font-size: 1rem;             cursor: pointer;             transition: background 0.3s;             height: 43px;             padding-top: 13px;             display: flex;             gap: 5px;         }         button:hover {             background: #ff4757;         }         .todo {             background: rgba(255, 255, 255, 0.2);             border-radius: 8px;             margin-top: 1rem;             display: flex;             justify-content: space-between;             align-items: center;             padding: 0.8rem;             box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);             transition: transform 0.2s, background 0.3s;         }         .todo:hover {             transform: translateY(-3px);             background: rgba(255, 255, 255, 0.3);         }         .task {             flex: 1;             font-size: 1rem;         }         .delete {             cursor: pointer;             transition: transform 0.2s, color 0.3s;         }         .delete:hover {             transform: scale(1.1);             color: #ff4757;         }         svg {             fill: currentColor;         }         #header {             position: relative;             left: 20px;         }         #mains {             width: 100%;             display: flex;         }     </style> </head> <body>     <div class="container">         <h1 id="header">Task Management App</h1>         <div id="mains">             <input type="text" placeholder="Enter a new task">             <button><span>Add</span> <span>Task</span></button>         </div>         <div id="task-list"></div>     </div>    <script src ="index.js"></script> </body> </html> 

Explanation of the Code

  1. HTML Structure
    1. The container div holds all elements, including an input field, a button, and a task list.
    2. Tasks will dynamically populate the task-list div.
  2. CSS Styling
    1. Provides a modern, centered design with a dark background and contrasting light content.
    2. The .todo class styles individual task items with hover effects.

Task Management App- Typescript Logic

The TypeScript code handles the app's functionality, such as adding, deleting, and persisting tasks. It is structured with type safety and reusable functions.

JavaScript
interface Task {     id: number;     text: string; }  const inputs = document.querySelector('input') as HTMLInputElement; const btn = document.querySelector('button') as HTMLButtonElement; const taskList = document.getElementById('task-list') as HTMLElement; let task: Task[] = [];  // Check if there is any task data in localStorage const localstoragedata = localStorage.getItem("task array");  if (localstoragedata !== null) {     const ogdata: Task[] = JSON.parse(localstoragedata);     task = ogdata;     maketodo(); }  btn.addEventListener("click", function () {     const query = inputs.value;     inputs.value = "";      if (query.trim() === "") {         alert("no value entered");         throw new Error("empty input field error");     }      // Create a task object     const taskObj: Task = {         id: Date.now(),         text: query     };      // Add the new task to the array     task.push(taskObj);     localStorage.setItem("task array", JSON.stringify(task));     maketodo(); });  function maketodo(): void {     taskList.innerHTML = "";      // Iterate over each task and create the UI elements     for (let i = 0; i < task.length; i++) {         const { id, text } = task[i];         const element = document.createElement('div');         element.innerHTML = `             <span class="task">${text}</span>             <span class="delete">                 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">                     <path d="M17 6H22V8H20V21C20 21.5523                      19.5523 22 19 22H5C4.44772 22 4 21.5523                      4 21V8H2V6H7V3C7 2.44772 7.44772 2 8                       2H16C16.5523 2 17 2.44772 17 3V6ZM18                       8H6V20H18V8ZM13.4142 13.9997L15.182                       15.7675L13.7678 17.1817L12 15.4139L10.2322                       17.1817L8.81802 15.7675L10.5858 13.9997L8.81802                        12.232L10.2322 10.8178L12 12.5855L13.7678                         10.8178L15.182 12.232L13.4142 13.9997ZM9                          4V6H15V4H9Z"></path>                 </svg>             </span>         `;                  // Handle the delete button click event         const delbtn = element.querySelector('.delete')!;         delbtn.addEventListener("click", function () {             // Remove the task from the array based on its ID             const filteredarray = task.filter((taskobj: Task) => taskobj.id !== id);             task = filteredarray;             localStorage.setItem("task array", JSON.stringify(task));             taskList.removeChild(element);         });          element.classList.add('todo');         taskList.appendChild(element);     } } 

In this example

  • Task Interface: Defines task structure (id and text).
  • Element Selection: Selects input, button, and task list with type assertions.
  • Load Tasks: Retrieves tasks from localStorage and displays them on page load.
  • Add Task: On button click, adds a new task to the list and localStorage.
  • Render Tasks: Displays tasks in the UI, with a delete button for each task.
  • Delete Task: Removes tasks from the list and localStorage when the delete button is clicked.
  • Persistence: Saves tasks in localStorage for persistence across page refreshes.

Convert to JavaScript File

Now You need to convert the TypeScript file into JavaScript to render by browser. Use one of the following command-

npx tsc task.ts
tsc task.ts
  • The command tsc task.ts compiles the calculator.ts TypeScript file into a task.js JavaScript file.
  • It places the output in the same directory as the input file by default.

Complete Code

HTML
<html> <head>     <style>         body {             font-family: 'Arial', sans-serif;             background-color: black;             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             margin: 0;             color: #fff;         }         .container {             background: rgba(255, 255, 255, 0.1);             padding: 2rem;             border-radius: 15px;             box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);             width: 100%;             max-width: 400px;         }         input[type="text"] {             width: calc(100% - 100px);             padding: 0.8rem;             border-radius: 8px;             border: none;             outline: none;             font-size: 1rem;             margin-right: 1rem;             box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);         }         button {             box-sizing: border-box;             padding: 0.8rem 1rem;             border-radius: 8px;             border: none;             background: #ff6b6b;             color: #fff;             font-size: 1rem;             cursor: pointer;             transition: background 0.3s;             height: 43px;             padding-top: 13px;             display: flex;             gap: 5px;         }         button:hover {             background: #ff4757;         }         .todo {             background: rgba(255, 255, 255, 0.2);             border-radius: 8px;             margin-top: 1rem;             display: flex;             justify-content: space-between;             align-items: center;             padding: 0.8rem;             box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);             transition: transform 0.2s, background 0.3s;         }         .todo:hover {             transform: translateY(-3px);             background: rgba(255, 255, 255, 0.3);         }         .task {             flex: 1;             font-size: 1rem;         }         .delete {             cursor: pointer;             transition: transform 0.2s, color 0.3s;         }         .delete:hover {             transform: scale(1.1);             color: #ff4757;         }         svg {             fill: currentColor;         }         #header {             position: relative;             left: 20px;         }         #mains {             width: 100%;             display: flex;         }     </style> </head> <body>     <div class="container">         <h1 id="header">Task Management App</h1>         <div id="mains">             <input type="text" placeholder="Enter a new task">             <button><span>Add</span> <span>Task</span></button>         </div>         <div id="task-list"></div>     </div>     <script>         var inputs = document.querySelector('input');         var btn = document.querySelector('button');         var taskList = document.getElementById('task-list');         var task = [];         var localstoragedata = localStorage.getItem("task array");         if (localstoragedata !== null) {             var ogdata = JSON.parse(localstoragedata);             task = ogdata;             maketodo();         }         btn.addEventListener("click", function () {             var query = inputs.value;             inputs.value = "";             if (query.trim() === "") {                 alert("no value entered");                 throw new Error("empty input field error");             }             var taskObj = {                 id: Date.now(),                 text: query             };             task.push(taskObj);             localStorage.setItem("task array", JSON.stringify(task));             maketodo();         });         function maketodo() {             taskList.innerHTML = "";             for (var i = 0; i < task.length; i++) {                 var _a = task[i], id = _a.id, text = _a.text;                 var element = document.createElement('div');                 element.innerHTML = "\n            <span class=\"task\">".concat(text, "</span>\n            <span class=\"delete\">\n                <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\">\n                    <path d=\"M17 6H22V8H20V21C20 21.5523 19.5523 22 19 22H5C4.44772 22 4 21.5523 4 21V8H2V6H7V3C7 2.44772 7.44772 2 8 2H16C16.5523 2 17 2.44772 17 3V6ZM18 8H6V20H18V8ZM13.4142 13.9997L15.182 15.7675L13.7678 17.1817L12 15.4139L10.2322 17.1817L8.81802 15.7675L10.5858 13.9997L8.81802 12.232L10.2322 10.8178L12 12.5855L13.7678 10.8178L15.182 12.232L13.4142 13.9997ZM9 4V6H15V4H9Z\"></path>\n                </svg>\n            </span>\n        ");                 // Handle the delete button click event                 var delbtn = element.querySelector('.delete');                 delbtn.addEventListener("click", function () {                     // Remove the task from the array based on its ID                     var filteredarray = task.filter(function (taskobj) { return taskobj.id !== id; });                     task = filteredarray;                     localStorage.setItem("task array", JSON.stringify(task));                     taskList.removeChild(element);                 });                 element.classList.add('todo');                 taskList.appendChild(element);             }         }     </script> </body> </html> 

Next Article
Moment.js using with Typescript

S

sneha2dmo
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • TypeScript
  • TypeScript-Projects

Similar Reads

  • Task Manager App using MERN Stack
    Task Manager is very crucial to manage your tasks. In this article, we are going to develop a task manager application using the MERN stack. This application helps users to manage their tasks efficiently, offering essential features like creating new tasks, editing existing ones, and deleting tasks
    10 min read
  • Calculator App Using TypeScript
    A calculator app is a perfect project for practising TypeScript along with HTML and CSS. This app will have basic functionalities like addition, subtraction, multiplication, and division. It provides a clean and interactive interface for the user while using TypeScript to handle logic safely and eff
    6 min read
  • Quiz App Using Typescript
    A quiz app built with TypeScript provides an interactive way to test knowledge while using TypeScript’s strong typing for better code quality. By implementing features like multiple-choice questions, score tracking, and timers, we can create a robust and engaging quiz experience for users. What We’r
    7 min read
  • Moment.js using with Typescript
    In this article, we will learn how to use the Moment.js library with Typescript language. Typescript is a strongly-typed programming language that wraps JavaScript and gives it optional static typing. It is free and open source and is maintained by Microsoft.  Using Moment.js with Typescript: To use
    1 min read
  • TypeScript Using Class Types in Generics
    TypeScript Using class types in generics allows you to create more flexible and reusable code by specifying that a generic parameter should be a class constructor. This is particularly useful when you want to work with instances of classes but want to keep the code type safe. You can define a generi
    3 min read
  • Build a Task Management App using Next JS
    A Task management app is a useful web application that assists in efficiently organizing and managing tasks. It provides various functionalities such as creating tasks, assigning prioritie­s and deadlines, marking complete tasks, and enabling task search based on ke­ywords and priorities. Preview of
    5 min read
  • Build a Project Management Tool Using NextJS
    A project management tool is very crucial for organizing tasks which helps us to be productive. In this article, we will guide you through the process of building a simple project management tool using Next.js, a powerful React framework that allows you to build server-rendered React applications wi
    6 min read
  • Notes Maker App using MERN Stack
    The "Notes Maker" project is an helpful web application designed to help users effectively create, manage, and organize their notes. In this article we are utilizing the MERN (MongoDB, Express, React, Node) Stack, to build a notes maker application that provides a seamless user experience for note-t
    6 min read
  • How to Pass Over an Element Using TypeScript and jQuery ?
    This article will show how we can pass an HTML element to a function using jQuery and TypeScript together. There are different ways available in which we can pass an element to a function using TypeScript and jQuery as listed below. Before moving on to the implementation, make sure that you have jQu
    4 min read
  • How to Use MathJS with TypeScript?
    Math.js library can be use with TypeScript to handle various mathematical tasks while getting the benefits of TypeScript’s type safety and autocompletion. Integrating Math.js into your TypeScript project allows you to perform arithmetic, algebra, statistics, and more, with the added advantage of Typ
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences