Tsallaka zuwa abun ciki
Justice Tech School

Practice: Typed Todo List

Model data with an interface, then write small typed functions.

Example
interface Todo { id: number; text: string; done: boolean }
const add = (l: Todo[], text: string): Todo[] => [...l, { id: l.length + 1, text, done: false }];
const done = (l: Todo[], id: number) => l.map((t) => (t.id === id ? { ...t, done: true } : t));
let list: Todo[] = [];
list = add(list, "learn");
list = done(list, 1);
console.log(list);

Result

[
  {
    id: 1,
    text: "learn",
    done: true,
  }
]

Exercise

Boolean field.

done: 

Quiz Test

What returns a new list?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.