Skip to content

Instantly share code, notes, and snippets.

@amantulsyan35
Created November 25, 2023 22:00
Show Gist options
  • Save amantulsyan35/228392b03e0740ebdcd6499482771b98 to your computer and use it in GitHub Desktop.
Save amantulsyan35/228392b03e0740ebdcd6499482771b98 to your computer and use it in GitHub Desktop.
Concept of a todo app in typescript's type system
type List = string[];
type Add<T1 extends List, T2 extends string> = [...T1, T2];
type Remove<T1 extends List, T2 extends string> = T1 extends [T2, ...infer Rest]
? Rest
: T1;
type Tasks1 = Add<[], "Task 1">;
type Tasks2 = Add<Tasks1, "Task 2">;
type Tasks3 = Add<Tasks2, "Task 3">;
type TasksToRemove1 = Remove<Tasks3, "Task 2">;
type TasksToRemove2 = Remove<TasksToRemove1, "Task 1">;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment