Welcome! This repository contains a series of TypeScript exercises designed to help you practice and improve your type system skills.
The goal of these exercises is to add proper type annotations to functions that are currently working but not well-typed. All tests are already passing, so your job is to improve the type safety of the codebase by replacing implicit any types with proper TypeScript types.
Complete the exercises in the following order:
- addNumbers - Start with basic number typing
- addStrings - Practice string-specific typing
- attempt - Handle function and error typing
- constant - Work with generic types
- identity - Master generics and optional parameters
- noop - Type functions with arbitrary arguments
- times - Combine generics with function callbacks
Each function in the src/ directory has tests that are passing, but the functions lack proper type annotations. Your job is to:
- Add appropriate type annotations to function parameters
- Add return type annotations where helpful
- Use generics (
<T>) when appropriate - Replace any implicit
anytypes with specific types - Ensure type safety while maintaining the existing functionality
any type found in your code costs 5 euros, and you have a 20 euro credit to use during this session.
This means you can have at most 4 instances of any in your codebase before you exceed your budget. Use your credit wisely!
- Use specific types (
string,number,boolean, etc.) - Use generics (
<T>,<U>, etc.) for functions that work with multiple types - Use union types (
string | number) when a value can be one of several types - Use
unknowninstead ofanywhen the type is truly unknown (though you'll still need to narrow it) - Use function types for callbacks and higher-order functions
-
Run the tests to see that they're passing:
npm test -
Start with the first exercise (
addNumbers) and work through them in order -
After adding types, run the tests again to ensure everything still works:
npm test -
Check for any
anytypes in your code - remember, each one costs 5 euros!
Take your time, think about the types carefully, and remember: the goal is type safety, not just making the tests pass (they already do!). Happy typing! 🎯