01 · Fundamentals of TypeScript
- : string / : number
- boolean
- inference
- T[]
- readonly [T, U]
End of the TypeScript Course
Congratulations! You have completed all 10 modules and 22 lessons of the TypeScript Course — from primitive annotations, interfaces, and discriminated unions to generics, mapped types, typed async concurrency, Result<T, E>, satisfies, and branded types.
TypeScript exercises are type-checked with strict: true and executed live in-browser in a sandboxed Web Worker against real unit tests; you can also open any snippet in the interactive Playground.
Combine what you mastered by building five runtime-verified strict components: generic firstElement<T>, optional-field getSalary, discriminated ApiResponse<T>, TaskManager with Omit<Task, ...>, and custom type guard isAdmin(user).
Write a generic helper taking T[] and returning the first item or undefined when empty (Module 3).
Define generic function firstElement<T>(arr: T[]): T | undefined returning arr[0].
Place <T> after the function name and return arr[0]; to preserve element types.
Solution available after 3 attempts
Declare Employee with optional salary?: number and getSalary(emp) returning salary or 0 (Module 2).
Define Employee (id: number, name: string, salary?: number) and getSalary(emp: Employee): number using nullish coalescing (?? 0).
Optional salary?: number is number | undefined; return emp.salary ?? 0 safely handles missing values.
Solution available after 3 attempts
Model ApiResponse<T> as Success<T> | Failure and narrow branches via res.status (Modules 2 & 3).
Implement handleResponse<T>(res: ApiResponse<T>): string returning "Data: " + res.data on "success" or "Error: " + res.message on "error".
Checking res.status === "success" automatically narrows res to Success<T>.
Solution available after 3 attempts
Derive NewTask = Omit<Task, "id" | "completed"> and implement TaskManager conforming to ITaskManager (Module 4).
Define type NewTask = Omit<Task, "id" | "completed">; then implement TaskManager with private tasks: Task[] = [] and private nextId: number = 1.
Inside addTask(task: NewTask), assign id: this.nextId++ and completed: false, push to this.tasks, and return newTask.
Solution available after 3 attempts
Write type predicate isAdmin(user: User): user is Admin and consume it inside getDashboardAccess (Module 5).
Implement isAdmin returning user.role === "admin", then implement getDashboardAccess returning "Admin Access: " + permissions or "Standard Access for " + username.
The predicate return type : user is Admin lets TypeScript narrow user inside if (isAdmin(user)).
Solution available after 3 attempts
One structured page covering basics, generics, mapped types, strict async/await, Result<T, E>, satisfies, and tsconfig flags.
Hands-on practice locks in type-level thinking. Launch the live TypeScript Playground to compile strict code in-browser or prototype real pipelines.